-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for apps loaded from Windows file shares #2774
Conversation
…k drives When loading an application from a Windows file share (not mapped to a network letter), Chrome will throw an error ("cannot be created in a document with origin 'null'") when `replaceState` is called. This happens because while `protocol` is `file:` and `host` is `vboxsvr` the `origin` is `file://` as opposed to `file://vboxsvr`. This means the absolute path is not created correctly. Only Windows shares that are not mapped to a drive letter are affected. If a drive letter is mapped then while origin will still be `file://`, pathname will include the information instead (e.g. `/Z:/dist/index.html`) This code removes the reliance on the origin attribute and calculates the absolute path from `protocol` and `host`.
hey, thanks for the PR, do you have a repro when this happens (the content of an HTML file) + repro steps? |
@posva, I've got a large app that has the issue. It should be easy enough to create a small test case though provided a VM can be setup with the right network shares (I did it just using Virtualbox). Would you like me to create a small app to reproduce it? |
yes, please the boiled down repro would be nice (fits in one small HTML file). Regarding the URL, shouldn't it also happen on UNIX-based filesystems |
Okay I've got a demo here: https://gist.github.com/theozaurus/7a13df223772a4e9b3459d9017eb0079 It works fine on a UNIX-based filesystem as the URL will be |
Great, thank you very much for the indications, I will take a look in the following weeks! |
Hey @theozaurus, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚 |
Hi, window.history.replaceState(null, '', '/C:/2774_example.html'); // URL will become "file:///C:/C:/2774_example.html" but such kind of calls will work perfectly: window.history.replaceState(null, '', 'C:/2774_example.html'); // URL will become "file:///C:/2774_example.html" For now, I made an ugly workaround to overwrite method And here is my workaround: function detectIE() {
if (!window || !window.navigator || !window.navigator.userAgent) {
return false;
}
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return true;
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
return true;
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return true;
}
// other browser
return false;
}
if (detectIE()) {
let oldReplaceState = window.history.replaceState;
window.history.replaceState = function(...args) {
let matches,
newArgs = [...args];
if (
newArgs.length >= 3 &&
newArgs[2] &&
// URLs like '/C:/my/path/to/2774_example.html' will be rewritten as 'my/path/to/2774_example.html'
(matches = /^\/[A-Z]:(\/.*)$/gi.exec(newArgs[2].toString())) &&
matches.length == 2
) {
newArgs[2] = matches[1];
}
return oldReplaceState.apply(this, newArgs);
};
} I don't know if there is much to do in vue-router's code to fix such kind of issue, but I wanted at least to share my workaround if some other people have same problem ;) |
When loading an application from a Windows file share (not mapped to a network letter), Chrome will throw an error (
cannot be created in a document with origin 'null'
) whenreplaceState
is called. This happens because whileprotocol
isfile:
andhost
isvboxsvr
theorigin
isfile://
as opposed tofile://vboxsvr
. This means the absolute path is not created correctly.Only Windows shares that are not mapped to a drive letter are affected. If a drive letter is mapped then while origin will still be
file://
, pathname will include the information instead (e.g./Z:/dist/index.html
)This code removes the reliance on the origin attribute and calculates the absolute path from
protocol
andhost
.