Skip to content

Commit

Permalink
fix(agent): create navigation for empty frame
Browse files Browse the repository at this point in the history
Fix for Hero #255
  • Loading branch information
blakebyrnes committed Mar 30, 2024
1 parent 06cf6d0 commit 69d90aa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 49 deletions.
5 changes: 5 additions & 0 deletions unblocked/agent/main/lib/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ export default class Frame extends TypedEventEmitter<IFrameEvents> implements IF
loader.setNavigationResult(frame.url);
}

if (this.isDefaultUrl && this.parentId && !this.navigations.top) {
const top = this.navigations.onNavigationRequested('newFrame', this.url, 0, loader.id);
this.navigations.setPageReady(top, Date.now());
}

this.emit('frame-navigated', { frame: this, loaderId: frame.loaderId });
}

Expand Down
14 changes: 13 additions & 1 deletion unblocked/agent/main/test/Frames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Helpers, TestLogger } from '@ulixee/unblocked-agent-testing/index';
import { inspect } from 'util';
import { Browser, BrowserContext, Page } from '../index';
import Agent from '../lib/Agent';
import { attachFrame, setContent } from './_pageTestUtils';
import { attachFrame, setContent, waitForExists } from './_pageTestUtils';
import { TestServer } from './server';

describe('Frames', () => {
Expand Down Expand Up @@ -115,6 +115,18 @@ describe('Frames', () => {
expect(a2).toBe(2);
});

it('should be able to wait for JavascriptReady in a srcdoc frame', async () => {
await page.goto(`${server.baseUrl}/frames/empty-frame.html`);
await expect(page.waitForLoad('AllContentLoaded', { timeoutMs: 1000 })).resolves.toBeTruthy();
await waitForExists(page.mainFrame, '#frame1', 1000);
if (page.frames.length === 1) {
await page.waitOn('frame-created', ev => ev.frame.id === 'frame1', 2000);
}
await expect(
page.frames[1].waitForLoad({ loadStatus: 'JavascriptReady', timeoutMs:1000 }),
).resolves.toBeTruthy();
});

it('should work in iframes that failed initial navigation', async () => {
// - Firefox does not report domcontentloaded for the iframe.
// - Chromium and Firefox report empty url.
Expand Down
12 changes: 12 additions & 0 deletions unblocked/agent/main/test/_pageTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ export async function waitForVisible(frame: Frame, selector: string, timeoutMs =
return visibility;
}

export async function waitForExists(frame: Frame, selector: string, timeoutMs = 10e3): Promise<void> {
await wait(
async () => {
const visibility = await frame.jsPath.getNodeVisibility(['document', ['querySelector', selector]]);
if (visibility.nodeExists) {
return true;
}
},
{ loopDelayMs: 100, timeoutMs },
);
}

function wait(
callbackFn: () => Promise<boolean>,
options: { timeoutMs?: number; loopDelayMs?: number } = {},
Expand Down
15 changes: 15 additions & 0 deletions unblocked/agent/main/test/assets/frames/empty-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>
<body>
<p>This test includes an iframe with an about:blank src into which we inject javascript</p>
<iframe id="frame1" src="about:blank"></iframe>
<script>
function Load() {
const frameEl = document.getElementById('frame1');
const frameWin = frameEl.contentWindow;
const el = document.createElement('div');
el.textContent = 'injected text';
frameWin.document.body.appendChild(el);
}
</script>
</body>
</html>
86 changes: 38 additions & 48 deletions unblocked/double-agent/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,25 @@
"@typescript-eslint/types" "6.20.0"
eslint-visitor-keys "^3.4.1"

"@ulixee/[email protected].25":
version "2.0.0-alpha.25"
resolved "https://registry.yarnpkg.com/@ulixee/js-path/-/js-path-2.0.0-alpha.25.tgz#a4e6c526f4e65931dd30f77403985483f565bb70"
integrity sha512-FLguWO0+4UN3a7Hk+RaF8/Uga3xE0riJgtgEe7emMwZ1e6rgmLkygxIxbW3B2rKrcjoIa/xygjt2S7T7zEtqUg==

"@ulixee/[email protected].25":
version "2.0.0-alpha.25"
resolved "https://registry.yarnpkg.com/@ulixee/real-user-agents/-/real-user-agents-2.0.0-alpha.25.tgz#27272d8464b5fb971a0b84bf8f98eacc1e282c00"
integrity sha512-dlpu+Ky2uCO4hvX+lbuEmWz06vRQipRgRNQxT/4MNfyKP7hGiddF8nZpURklYjtrsyRpgMdCNTMcTfniKEHHbw==
dependencies:
"@ulixee/commons" "2.0.0-alpha.25"
"@ulixee/unblocked-specification" "2.0.0-alpha.25"
compare-versions "^3.6.0"
ua-parser-js "^0.7.24"

"@ulixee/repo-tools@^1.0.27":
version "1.0.27"
resolved "https://registry.yarnpkg.com/@ulixee/repo-tools/-/repo-tools-1.0.27.tgz#c5e8be7f0bbb0ebb2d791410f866af86259a8db7"
integrity sha512-P887ZWkP3G+ocdb3bxWTbm7mHXMuTvpkTsGMci+Co4jVd0eObfP42jLVtuilsUiyWJ9a8i8WGbe6p1opbhTHqg==
"@ulixee/[email protected].28":
version "2.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@ulixee/js-path/-/js-path-2.0.0-alpha.28.tgz#6051bf2bc702352019859a0d9b61c7513f1b3740"
integrity sha512-wn05oPwSq3g4+pjmP1EKAf5BgzZswnYEkjm5SB7pfLgASgHiYfkKTTjhCz1PUs+JN+KVW1RmvQCjetPXD9EW7A==

"@ulixee/[email protected].28":
version "2.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@ulixee/real-user-agents/-/real-user-agents-2.0.0-alpha.28.tgz#e218ff5d06d95ee6a63393e3e41582d5a88ff632"
integrity sha512-Zxlua5Mnhpe7254rWS8AF7DqPNiKSneBR/E/k8COQdlR+wiCiNord95Gvbigf/cLdQO0ShiDLodY/vCnnaHYeQ==
dependencies:
"@ulixee/commons" "2.0.0-alpha.28"
"@ulixee/unblocked-specification" "2.0.0-alpha.28"
compare-versions "^6.1.0"
ua-parser-js "^1.0.37"

"@ulixee/repo-tools@^1.0.29":
version "1.0.29"
resolved "https://registry.yarnpkg.com/@ulixee/repo-tools/-/repo-tools-1.0.29.tgz#aa90ea63b8bbfa7a84ac081988ae3d6acee00fe1"
integrity sha512-cga/4OfcTN5GxYSHhPdXHEZFykUt4uIqkl+T4QZ5rH4CXndt8pq4SvoQw1KSG9u3eNMu+yHmLc4iMZGYS/UavA==
dependencies:
"@typescript-eslint/eslint-plugin" "^6.20.0"
"@typescript-eslint/parser" "^6.20.0"
Expand All @@ -394,12 +394,12 @@
pretty-quick "^4.0.0"
typescript "^5.3.3"

"@ulixee/[email protected].25":
version "2.0.0-alpha.25"
resolved "https://registry.yarnpkg.com/@ulixee/unblocked-specification/-/unblocked-specification-2.0.0-alpha.25.tgz#671ff03c05aa0d221ea3213628e2aa9629c61118"
integrity sha512-Ka2x0YiMQPKEPs5iDSE/bYLRilM0MkqFe/4P8Wy/DJ805S+nwrx6tFwcbrgPuc7aFrnlzuP6ndF8hV32sbSOVg==
"@ulixee/[email protected].28":
version "2.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@ulixee/unblocked-specification/-/unblocked-specification-2.0.0-alpha.28.tgz#41344696d3732e0062cccbfcd5dc16b62fad28fe"
integrity sha512-5BFYwyT6GBiy8yVw/piFNSACgv2FBJvJzDTVnSCnW9PSKTjIu6H7w7T/0uhCGVsW8hS91v+SjMLlaEv0c1GKqg==
dependencies:
"@ulixee/js-path" "2.0.0-alpha.25"
"@ulixee/js-path" "2.0.0-alpha.28"
devtools-protocol "^0.0.1137505"

"@ungap/structured-clone@^1.2.0":
Expand Down Expand Up @@ -586,11 +586,6 @@ bech32@^2.0.0:
resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355"
integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==

bignumber.js@^9.0.2:
version "9.1.2"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c"
integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down Expand Up @@ -694,15 +689,15 @@ combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"

commander@^9.0.0, commander@^9.3.0:
commander@^9.5.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==

compare-versions@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
integrity sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==
compare-versions@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.1.0.tgz#3f2131e3ae93577df111dba133e6db876ffe127a"
integrity sha512-LNZQXhqUvqUTotpZ00qLSaify3b4VFD588aRr8MKFw4CMUr98ytzCW5wDH5qx/DEY5kCDXcbcRuCqL0szEf2tg==

[email protected]:
version "0.0.1"
Expand Down Expand Up @@ -2674,10 +2669,10 @@ tapable@^2.2.0:
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==

tar@^6.1.15:
version "6.2.0"
resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.0.tgz#b14ce49a79cb1cd23bc9b016302dea5474493f73"
integrity sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==
tar@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/tar/-/tar-6.2.1.tgz#717549c541bc3c2af15751bea94b1dd068d4b03a"
integrity sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==
dependencies:
chownr "^2.0.0"
fs-minipass "^2.0.0"
Expand Down Expand Up @@ -2809,10 +2804,10 @@ typescript@^5.3.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==

ua-parser-js@^0.7.24:
version "0.7.37"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.37.tgz#e464e66dac2d33a7a1251d7d7a99d6157ec27832"
integrity sha512-xV8kqRKM+jhMvcHWUKthV9fNebIzrNy//2O9ZwWcfiBFR5f25XVZPLlEajk/sf3Ra15V92isyQqnIEXRDaZWEA==
ua-parser-js@^1.0.37:
version "1.0.37"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.37.tgz#b5dc7b163a5c1f0c510b08446aed4da92c46373f"
integrity sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==

unbox-primitive@^1.0.2:
version "1.0.2"
Expand Down Expand Up @@ -2943,7 +2938,7 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==

ws@^7.4.6:
ws@^7.5.9:
version "7.5.9"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==
Expand Down Expand Up @@ -2990,8 +2985,3 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zod@^3.20.2:
version "3.22.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff"
integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==

0 comments on commit 69d90aa

Please sign in to comment.