Repository navigation
Propose visits for window.open() calls, not only target="_blank" links - #227
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
onCreateWindow() recovered the new window's url with requestFocusNodeHref(), which reads the href of the focused anchor. A window.open() call has no anchor, so no url was found and the tap silently did nothing. Back the new window with a placeholder WebView instead, handed to the WebViewTransport, and propose a visit to the first location it's asked to load. This observes the actual navigation, so it covers target="_blank" links and window.open() alike, including from iframes and windows that are opened first and given a location afterwards. The window is never shown and is destroyed once its location is known, when it's closed, or when another window replaces it. Fixes hotwired#212
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #212
HotwireWebChromeClient.onCreateWindow()recovered the new window's url withrequestFocusNodeHref(), which reads thehrefof the focused anchor. Awindow.open()call has no anchor, so no url was found and the tap silently did nothing.target="_blank"links kept working, which hid the problem until content opened links from JavaScript.This hands the
WebViewTransporta placeholderWebViewand proposes a visit to the first location it's asked to load (shouldOverrideUrlLoading(), withonPageStarted()as a fallback). Because it observes the actual navigation instead of inferring it from DOM focus, it covers:target="_blank"links, as beforewindow.open(url), at the top level and inside iframesconst w = window.open(); w.location = url. The initialabout:blankload is ignored.The placeholder is never shown or attached. It's destroyed once its location is known, when the page calls
close()on it, or when another window replaces it, so at most one is ever kept around. It's destroyed on the next main-loop pass because this can happen inside one of its own client callbacks.onCreateWindow()now returnstruewhen it handles the window, as theWebChromeClientcontract requires after sending the transport message. It still returnsfalsewhen there's no transport. Windows opened without a user gesture are still blocked by the WebView, becausejavaScriptCanOpenWindowsAutomaticallystays at its default offalse.Added
HotwireWebChromeClientTest, which covers proposing the visit from both callbacks, proposing only one visit per window, ignoringabout:blank, and destroying the window in each case. 8 of the 9 tests fail without the change.