GWT 2.0 + chrome = Unsafe JavaScript attempt to access frame with URL …

Problem description

Some time ago I have made some application in GWT 2.0, then I have compiled it and wanted to test it under Chrome browser. The effect was suprising.. google product does not work with another google product. … I have got an error message from Chrome Console:

Unsafe JavaScript attempt to access frame with URL file:///C:/workspace/war/Blog_Demonstrations.html       from frame with URL file:///C:/workspace/war/blog_demonstrations/3AA8DD86E4E2DF30F0E5F461485CF698.cache.html.  Domains, protocols and ports must match.

followed by:

Uncaught TypeError: Property ‘gwtOnLoad’ of object [object DOMWindow] is not a function

Anyway I have uploaded my application on a web-server and it appeared to work.

Why there is an error

Today I had the same problem so I’ve investigated it a little bit more.. What I have found out is : this is Chrome problem (calling it bug may be to harsh). It happens because Chrome has stricter Same-Origin-Policy than another browsers.  This policy doesn’t allow web-applications to open (via JavaScirpt) files from the file-system (they apparently are not from the same origin;] ).

Workaround solution    for testing your application on local enviroment

Solution for this problem may be sending your static HTML page files to web server. You can even use your local Server (like Jetty).

I am using temporary solution to test my compiled GWT applications under Chrome browser:

0)  launch Launch your project in development mode ( Ctrl+ F11 in Eclipse). ( The point is just to launch the server)

1)  add folder In war directory of your application create folder “chrome-test

2) gwt icon Compile your GWT project . ( all static output should be created )

3) copy Copy all output to chrome-test directory. But remember NOT TO copy WEB-INF directory. My war folder after doing this operation looks like this:war directory

4) go to web site go to  http://127.0.0.1:YOUR_PORT_NUMBER/chrome-test/YOUR_INDEX.HTML

What you will see, will be compiled static gwt-page.  You can see difference between compiled page and page hosted by server by calling

GWT.isScript()

Method. If it will return true it means that page you are viewing was generated by JavaScript, otherwise what you are looking at was generated by bytecode (so it is hosted java code).

Links

bug trace from chrome dev site: http://code.google.com/p/chromium/issues/detail?id=31068


Advertisements