gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 374 forks source link

window.postMessage() events from parent frame clears GWT's URL parameters and place tokens #10018

Open vasanthnataraj opened 5 hours ago

vasanthnataraj commented 5 hours ago

GWT version:2.11.0 Browser (with version):chrome **Operating System:chrome 130


Description
Steps to reproduce

When there is a event received from the parent frame (window.postmessage()) to a child frame , In this case the GWT app is loaded in the chhild frame. The window.Location.getHref() returns only the base URL , all other parameters and place tokens are removed from the GWT URL.

Known workarounds
Links to further discussions
jnehlmeier commented 5 hours ago

The JS code of your GWT app lives in an iframe that the app creates for you. This is controlled by GWT's linker and by default the xsiframe linker is used.

So it is like:

iframe (2) stores the GWT URL parameters and place tokens. iframe (3) does not have any href at all.

So now it is important that you tell us what exactly is window.Location.getHref()? Is it GWT SDK Java code? Is it JS code via JSNI? Is it elemental2 library code? How do you obtain the window variable?

If it is JS code via JSNI in your GWT app then window points to iframe (3) and it is expected that you receive the base URL. The reason is that iframe (3) does not have any href and the browser returns the base URL of iframe (2). In that case you would need to use $wnd instead of window, because it will point to the window object of iframe (2) as you would expect.

vasanthnataraj commented 4 hours ago

The Window.Location.getHref()) is a GWT SDK Javacode [com.google.gwt.user.client] . Window.Location.getHref()) returns the parameters and place tokens correctly at all times, but if the GWT APP receives an window.postmessage event from the parent page then Window.Location.getHref()) returns the base url + the eventmessage

For Example:

we have a simple html page which has a iframe in it. Inside the iframe we have our GWT application loaded.

(1 - Parent) The simple html page fires window.postmessage(HelloMessage) via javascript to the GWT APP (2 - Child) GWT app -> receives event hellomessage. Now Window.Location.getHref() returns only the base url+eventmessage

GWT APP Before Event received from parent

Window.Location.getHref() returns http://127.0.0.1//mygwtapp.html?loginPlace=true&userId=8&loginId=9. ---(Correct)

GWT APP After Event received from parent

Window.Location.getHref() returns http://127.0.0.1//mygwtapp.htmlHelloMessage ---(Wrong)

jnehlmeier commented 4 hours ago

GWT's Window.Location.getHref() simply calls JS $wnd.location.href with $wnd pointing to your GWT app iframe window. Also GWT SDK does not have any postMessage code or message event handler code. So GWT itself will not change the href.

If something changes the href then the browser usually loads the new href. In your example I would expect a HTTP 404 NOT FOUND for the new iframe href because mygwtapp.htmlHelloMessage surely doesn't exist. So it is pretty weird if you receive a different href as you said.

I assume it is something in your app or a browser bug. Can you reproduce it in a small app?