Skip to content

Commit

Permalink
Handle iframe with src="about:blank" (#84)
Browse files Browse the repository at this point in the history
* Write e2e test case for <iframe src="about:blank">

* Fix edge case

---------

Co-authored-by: Andrew Hyndman <[email protected]>
  • Loading branch information
ajhyndman and Andrew Hyndman authored Apr 3, 2024
1 parent 505a5b6 commit 602093a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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';

// 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);
});
});

0 comments on commit 602093a

Please sign in to comment.