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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/networkIdleObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ResourceLoadingIdleObservable {
(element instanceof HTMLImageElement && element.complete) ||
(element instanceof HTMLLinkElement && !element.href) ||
(element instanceof HTMLScriptElement && !element.src) ||
(element instanceof HTMLIFrameElement && !element.src)
(element instanceof HTMLIFrameElement && (!element.src || element.src === 'about:blank'))
) {
return;
}
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/iframe3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<head>
<script src="/dist/index.min.js"></script>
<script src="/analytics.js"></script>
</head>

<body>
<h1 id="h1">Hello world!</h1>

<script>
// <iframe src="/stub.html?delay=500"></iframe>
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
Contributor

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. 🤷


// append iframe after "load" event fires
window.addEventListener('load', () => document.body.appendChild(iframe));
</script>
</body>
20 changes: 20 additions & 0 deletions test/e2e/iframe3/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {test, expect} from '@playwright/test';

import {FUDGE} from '../../util/constants';
import {getEntries} from '../../util/entries';

const PAGELOAD_DELAY = 200;

test.describe('TTVC', () => {
test('an iframe with src="about:blank"', async ({page}) => {
await page.goto(`/test/iframe3?delay=${PAGELOAD_DELAY}`, {
waitUntil: 'networkidle',
});

const entries = await getEntries(page);

expect(entries.length).toBe(1);
expect(entries[0].duration).toBeGreaterThanOrEqual(PAGELOAD_DELAY);
expect(entries[0].duration).toBeLessThanOrEqual(PAGELOAD_DELAY + FUDGE);
});
});
Loading