Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire a load event for javascript: URL non-strings #10957

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zcorpan
Copy link
Member

@zcorpan zcorpan commented Jan 28, 2025

Fixes #1895.

(See WHATWG Working Mode: Changes for more details.)


/browsing-the-web.html ( diff )
/iframe-embed-object.html ( diff )

@zcorpan
Copy link
Member Author

zcorpan commented Jan 28, 2025

I suppose the PR matches Chrome in that a load event is fired for a javascript: URL in the src attribute unconditionally, but like Safari to evaluate the javascript: URL lazily for loading=lazy iframes.

@domenic
Copy link
Member

domenic commented Jan 30, 2025

Just noting that this is on my queue, although @domfarolino and @natechapin might also be interested.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the end result here is fine, but the spec is so ugly 😅. I wonder how this is implemented in WebKit and Blink, and if it is similarly ugly or if it falls out more naturally in some way?

One idea would be that instead of passing a parameter to navigate, you always check if the "navigate to a javascript: URL" is being performed in a child navigable, and if so, fire the event on the navigable container? That would be different than this in that:

  • It would also fire load events for embed and object
  • It would also fire if code did iframe.contentWindow.location.href = "javascript:undefined"

Maybe writing tests for those scenarios would be instructive?

@zcorpan
Copy link
Member Author

zcorpan commented Feb 4, 2025

Navigations to javascript:1 from location.href (or following a hyperlink) don't fire load in Safari/Chrome.
https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13473
https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13474

No load event for embed (following a hyperlink): https://software.hixie.ch/utilities/js/live-dom-viewer/saved/13476

<embed src="javascript:"> doesn't run the JS because it goes through fetch first.

@domenic
Copy link
Member

domenic commented Feb 5, 2025

Darn. I've asked @natechapin to see if we can understand Chromium's behavior better, and maybe find a more elegant solution inspired by that. But given what you've checked so far, this seems to be the best way forward.

@zcorpan zcorpan marked this pull request as ready for review February 5, 2025 21:43
@zcorpan
Copy link
Member Author

zcorpan commented Feb 5, 2025

An approach I considered was to check for javascript: URL in https://html.spec.whatwg.org/multipage/iframe-embed-object.html#process-the-iframe-attributes step 2.3 (which fires a load event for about:blank). But then lazy-loading wouldn't work (which it also doesn't in Chromium), which I think is surprising behavior.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 5, 2025

I've added more tests now in web-platform-tests/wpt#50193

@domenic
Copy link
Member

domenic commented Feb 17, 2025

Nate has gone out of office, and we seem to have landed something that caused a merge conflict on this. But I'd still like to help get this landed.

I noticed from the WPT results that WebKit passes 100% of these tests. Combined with Gecko's interest, that should suffice to land this.

However, I'd still like to make a last-ditch attempt at figuring out a nicer way to spec this. @annevk, would you or someone else from WebKit (maybe @cdumez?) be able to tell us how WebKit manages to pass all the tests? Is it via some sort of special "fire the load event" flag like this PR does, or is there something more elegant that doesn't require threading through as many layers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Iframe with initial javascript: source needs to fire the load event in various cases
2 participants