laurentj / slimerjs

A scriptable browser like PhantomJS, based on Firefox
http://slimerjs.org
Other
3k stars 259 forks source link

changeUrl() does not load JS file when the original url is the url of <script crossorigin="anonymous"> #448

Open wskorodecki opened 8 years ago

wskorodecki commented 8 years ago

I have problems when I use changeUrl() method to redirect each main resource (page) and JavaScript resources to a new URL (the same but with added query string parameters). This method breaks the flow of dependency injection. It does occur only on websites which are using inline require() method. Facebook is a good example, because there is <script>require("TimeSlice") (line 11). I could not find any other examples.

versions

Test script

Actual results:

Changing URL: https://www.facebook.com/ to: https://www.facebook.com/?myParam=myValue
Changing URL: https://static.xx.fbcdn.net/rsrc.php/v2/y-/r/wytNyhRQgmX.js to: https://static.xx.fbcdn.net/rsrc.php/v2/y-/r/wytNyhRQgmX.js?myParam=myValue

Script Error: [JavaScript Error: "ReferenceError: require is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 11}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 11

Script Error: [JavaScript Error: "ReferenceError: requireLazy is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 13}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 13

Script Error: [JavaScript Error: "ReferenceError: requireLazy is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 15}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 15

Script Error: [JavaScript Error: "ReferenceError: require is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 16}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 16

Script Error: [JavaScript Error: "ReferenceError: require is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 21}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 21

Script Error: [JavaScript Error: "TypeError: bigPipe is undefined" {file: "https://www.facebook.com/?myParam=myValue" line: 22}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 22

Script Error: [JavaScript Error: "ReferenceError: require is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 23}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 23

Script Error: [JavaScript Error: "TypeError: bigPipe is undefined" {file: "https://www.facebook.com/?myParam=myValue" line: 23}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 23

Script Error: [JavaScript Error: "ReferenceError: require is not defined" {file: "https://www.facebook.com/?myParam=myValue" line: 24}]
       Stack:
         -> https://www.facebook.com/?myParam=myValue: 24

Expected results:

No errors.

laurentj commented 8 years ago

I investigated and debug mode shows that these errors appear because the first script https://static.xx.fbcdn.net/rsrc.php/v2/y-/r/wytNyhRQgmX.js?myParam=myValue is not loaded.

It's not loaded because it seems there is a CORS issue, because of the crossorigin attribute on the <script> element (crossorigin="anonymous"). When this attribute is removed, the redirection is made and all work as expected.

Perhaps something is missing in the changeUrl() implementation?

wskorodecki commented 8 years ago

Perhaps something is missing in the changeUrl() implementation?

I've found newChannel2(), newChannelFromURI2() methods which are newer versions of the methods currently being used in SlimerJS. Perhaps they will allow to fix this bug but I don't know how to use them properly. More info here: https://dxr.mozilla.org/mozilla-central/source/netwerk/base/nsILoadInfo.idl https://lists.mozilla.org/pipermail/dev-platform/2015-May/010063.html

laurentj commented 8 years ago

which are newer versions of the methods currently being used in SlimerJS

I don't use newChannel()

wskorodecki commented 8 years ago

I don't use newChannel()

I've found it in the following files: src/modules/addon-sdk/sdk/deprecated/tab-browser.js method getChromeURLContents() src/modules/addon-sdk/sdk/net/url.js methods readAsync() and readURISync() src/modules/addon-sdk/sdk/url.js function toFilename() src/modules/slUtils.jsm method readChromeFile()

so you mean that these files are not a part of SlimerJS?

laurentj commented 8 years ago

src/modules/addon-sdk are external libs, not developed by myself, and both, readChromeFile() and the addon-sdk, are not used for the feature on which there is the bug.