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

Handle iframe with src="about:blank" #84

Merged
merged 2 commits into from
Apr 3, 2024
Merged

Handle iframe with src="about:blank" #84

merged 2 commits into from
Apr 3, 2024

Conversation

ajhyndman
Copy link
Member

It seems like some segment of the industry has landed on the use of src="about:blank" as a backward compatible alternative to generating an iframe with no src attribute.

https://stackoverflow.com/questions/5946607/is-an-empty-iframe-src-valid

https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/src

This change ensures that mounting an <iframe src="about:blank"> will not cause the ResourceIdleObservable class to stall.

const iframe = document.createElement('iframe');
// "src" is technically a required field in HTML iframes. Many libraries work around
// this by specifying the url "about:blank". we should handle this scenario.
iframe.src = 'about:blank';
Copy link
Collaborator

Choose a reason for hiding this comment

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

From https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/src

Note that programmatically removing an <iframe>'s src attribute (e.g. via Element.removeAttribute()) causes about:blank to be loaded in the frame.

Do you think it's worth having a test that simulates this (in other words, programmatically remove the src attribute)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did actually try this manually. In all of the browsers I have installed, the contents of the iframe may be about:blank, but the src attribute itself remains empty.

So I think this finding was a bit of a red herring on my part, and our existing code already handles that well. 🤷

@ajhyndman ajhyndman merged commit 602093a into main Apr 3, 2024
4 checks passed
@ajhyndman ajhyndman deleted the iframe-about-blank branch April 3, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants