requirejs/require-cs

cs files are undefined in windows phone 8 / 'access denied' in ie10

Closed this issue · 11 comments

I'm using cordova 2.6 with windows phone 8, and the cs! plugin returns undefined for all coffee files. The same code works in other platforms/browsers.IE/WP8 is painful as usual.

In IE10, i see an 'access denied' in the console. It cannot drill down to the exact line in the source, and shows the error line in index.html itself. On seeing the 'network' panel (yup ie10 has this too !), I can see that all js files are loaded correctly, and the last js files to be loaded were coffee-script.js and cs.js. It halted when trying to load the first coffee file. (I am using the file:// protocol... )

In WP8 (which uses IE10 internally), I dont see any error in the console of visual studio, its just that the objects returned by the cs! plugin are undefined.

My main goal is to get my requirejs/coffeescript app working in win phone 8. It works awesome in other platforms/browsers but all things M$... Much thanks in advance.

ok... the error is in cs.js line 58.... xhr.open('GET',url,true)...

I'll let @guybedford comment more on it, but my first thought is that you are hitting the XHR security restrictions. I do not recall the specific ones for IE10, but usually the access needs to be to resources that are underneath the document's directory. So if you are accessing the scripts in a directory above the html file, you might try moving the scripts underneath.

That still may not fix it. It could be that you may need to set a preference to allow local XHR calls for the WP8 app. However, I do not know that platform well enough to know for sure.

I suppose the first question is if you are making a cross-origin request here?

If so I did find a note about some issues here - http://www.nokia.net.co/sec_rookie/?p=103.

IE10 should support cross origin, but IE9 only supports XDomainRequest.

Perhaps try replacing the return new XMLHttpRequest(); on line 34 of cs.js with return new XDomainRequest(); and see if that works in IE10?

This will be included in the module soon anyway.

I'm not trying to make a cross-origin request. I want cs.js to be able to load coffee files from the filesystem of windows phone 8(which uses ie10) via cordova/phonegap. Requirejs is able to load js files correctly but not cs! plugin returns undefined for coffee files. The same code works in other platforms android,BB10,etc.
When i try to run the same code in a browser(ie10) via file:// protocol, its giving a script5: access denied.at cs.js line 58. The same code works in other desktop browsers and mobile platforms.

Ill try your suggestion of XDomainRequest and revert. Thanks.

Ok this is a restriction in using XHR to access the local file system. There are browser flags to doable this security precaution but I am not sure about Ie10.

The best route forward if there are no flags is to precompile the cs resources with a build. Depending on your requirements it can also be possible to precompile all files using the optimizeAllPluginResources build option. I have a version of require-cs with this support if you are interested. It really depends on your requirements for bundling.

No luck using XDomainRequest... same access denied scene..

yes i figured that precompiling would work somehow... but what would be the ideal development workflow for changes that keep happening... Can you suggest the best way to go about this... what is the optimizeAllPluginResources build option?
Also, is there any way to circumvent the XHR restriction for local filesystem in browser / cordova?

There should be a way.... how come requirejs can load the js files...but cs.js cannot load coffee files? There must be some way right?

I made some progress modifying line 58 of cs.js

xhr.open('GET', url, true);

becomes

 xhr.open('GET', "x-wmapp0://www/" + url, true);

It seems WP8 has added some awkward prefix/protocol.
Now all top level defines are working, but the inline asynchronous require is still returning undefined. Note that it works in all other platforms, so its not a conceptual error on my side...

In other words, cs! is working in define lines, but not in require lines...

Ahh.. no the problem was that i had to add the same x-wmapp0 prefix in the tpl! plugin i was using as well.

Moral of the story is that for WP8 local filesystem, x-wmapp0:// has to be added to the xhr url.
Whoever else has this issue, this is the scene.
Thanks.

Sounds like quite a work around. Typically plugins should support the "createXHR" hook allowing for this sort of thing to be patched in without needing to fork.