2019-05-29 23:49:44 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2019-05-29 23:49:44 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-23 05:18:46 +00:00
|
|
|
import expect from 'expect';
|
2024-01-11 14:26:02 +00:00
|
|
|
import type {CDPSession} from 'puppeteer-core/internal/api/CDPSession.js';
|
2024-01-04 06:51:47 +00:00
|
|
|
import {CDPSessionEvent} from 'puppeteer-core/internal/api/CDPSession.js';
|
2024-02-12 16:28:21 +00:00
|
|
|
import type {Page} from 'puppeteer-core/internal/api/Page.js';
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2023-10-11 17:21:50 +00:00
|
|
|
import {getTestState, launch} from './mocha-utils.js';
|
2023-04-25 13:02:25 +00:00
|
|
|
import {attachFrame, detachFrame, navigateFrame} from './utils.js';
|
2023-02-15 23:09:31 +00:00
|
|
|
|
2023-10-11 17:21:50 +00:00
|
|
|
describe('OOPIF', function () {
|
2020-04-09 05:56:25 +00:00
|
|
|
/* We use a special browser for this test as we need the --site-per-process flag */
|
2023-07-03 12:01:29 +00:00
|
|
|
let state: Awaited<ReturnType<typeof launch>>;
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
before(async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {defaultBrowserOptions} = await getTestState({skipLaunch: true});
|
|
|
|
|
|
|
|
state = await launch(
|
2020-05-07 10:54:55 +00:00
|
|
|
Object.assign({}, defaultBrowserOptions, {
|
2022-01-17 07:00:00 +00:00
|
|
|
args: (defaultBrowserOptions.args || []).concat([
|
|
|
|
'--site-per-process',
|
|
|
|
'--remote-debugging-port=21222',
|
2022-05-04 05:46:38 +00:00
|
|
|
'--host-rules=MAP * 127.0.0.1',
|
2022-01-17 07:00:00 +00:00
|
|
|
]),
|
2023-07-03 12:01:29 +00:00
|
|
|
}),
|
|
|
|
{after: 'all'}
|
2020-05-07 10:54:55 +00:00
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
beforeEach(async () => {
|
2024-02-05 09:43:37 +00:00
|
|
|
state.context = await state.browser.createBrowserContext();
|
2023-07-03 12:01:29 +00:00
|
|
|
state.page = await state.context.newPage();
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
afterEach(async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
await state.context.close();
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
after(async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
await state.close();
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2022-06-15 10:09:22 +00:00
|
|
|
|
2021-10-28 09:25:49 +00:00
|
|
|
it('should treat OOP iframes and normal iframes the same', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2021-10-28 09:25:49 +00:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('/empty.html');
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame2',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
await framePromise;
|
|
|
|
expect(page.mainFrame().childFrames()).toHaveLength(2);
|
|
|
|
});
|
|
|
|
it('should track navigations within OOP iframes', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
const frame = await framePromise;
|
|
|
|
expect(frame.url()).toContain('/empty.html');
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/assets/frame.html'
|
|
|
|
);
|
|
|
|
expect(frame.url()).toContain('/assets/frame.html');
|
|
|
|
});
|
|
|
|
it('should support OOP iframes becoming normal iframes again', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
const frame = await framePromise;
|
|
|
|
expect(frame.isOOPFrame()).toBe(false);
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
expect(frame.isOOPFrame()).toBe(true);
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(page, 'frame1', server.EMPTY_PAGE);
|
2021-10-28 09:25:49 +00:00
|
|
|
expect(frame.isOOPFrame()).toBe(false);
|
|
|
|
expect(page.frames()).toHaveLength(2);
|
|
|
|
});
|
|
|
|
it('should support frames within OOP frames', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const frame1Promise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2022-06-22 13:25:44 +00:00
|
|
|
const frame2Promise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 2;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/frames/one-frame.html'
|
|
|
|
);
|
|
|
|
|
|
|
|
const [frame1, frame2] = await Promise.all([frame1Promise, frame2Promise]);
|
|
|
|
|
2022-06-15 10:09:22 +00:00
|
|
|
expect(
|
|
|
|
await frame1.evaluate(() => {
|
|
|
|
return document.location.href;
|
|
|
|
})
|
|
|
|
).toMatch(/one-frame\.html$/);
|
|
|
|
expect(
|
|
|
|
await frame2.evaluate(() => {
|
|
|
|
return document.location.href;
|
|
|
|
})
|
|
|
|
).toMatch(/frames\/frame\.html$/);
|
2021-10-28 09:25:49 +00:00
|
|
|
});
|
|
|
|
it('should support OOP iframes getting detached', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
const frame = await framePromise;
|
|
|
|
expect(frame.isOOPFrame()).toBe(false);
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
expect(frame.isOOPFrame()).toBe(true);
|
2023-04-25 13:02:25 +00:00
|
|
|
await detachFrame(page, 'frame1');
|
2021-10-28 09:25:49 +00:00
|
|
|
expect(page.frames()).toHaveLength(1);
|
|
|
|
});
|
2022-03-09 11:24:17 +00:00
|
|
|
|
|
|
|
it('should support wait for navigation for transitions from local to OOPIF', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2022-03-09 11:24:17 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2022-03-09 11:24:17 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
2022-03-09 11:24:17 +00:00
|
|
|
|
|
|
|
const frame = await framePromise;
|
|
|
|
expect(frame.isOOPFrame()).toBe(false);
|
|
|
|
const nav = frame.waitForNavigation();
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(
|
2022-03-09 11:24:17 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
await nav;
|
|
|
|
expect(frame.isOOPFrame()).toBe(true);
|
2023-04-25 13:02:25 +00:00
|
|
|
await detachFrame(page, 'frame1');
|
2022-03-09 11:24:17 +00:00
|
|
|
expect(page.frames()).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2021-10-28 09:25:49 +00:00
|
|
|
it('should keep track of a frames OOP state', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
const frame = await framePromise;
|
|
|
|
expect(frame.url()).toContain('/empty.html');
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(page, 'frame1', server.EMPTY_PAGE);
|
2021-10-28 09:25:49 +00:00
|
|
|
expect(frame.url()).toBe(server.EMPTY_PAGE);
|
|
|
|
});
|
2022-09-08 10:32:39 +00:00
|
|
|
|
2021-10-28 09:25:49 +00:00
|
|
|
it('should support evaluating in oop iframes', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
const frame = await framePromise;
|
|
|
|
await frame.evaluate(() => {
|
2024-06-10 15:54:55 +00:00
|
|
|
(window as any)._test = 'Test 123!';
|
2021-10-28 09:25:49 +00:00
|
|
|
});
|
|
|
|
const result = await frame.evaluate(() => {
|
2024-06-10 15:54:55 +00:00
|
|
|
return (window as any)._test;
|
2021-10-28 09:25:49 +00:00
|
|
|
});
|
|
|
|
expect(result).toBe('Test 123!');
|
|
|
|
});
|
|
|
|
it('should provide access to elements', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, isHeadless, headless, page} = state;
|
2022-06-10 10:39:18 +00:00
|
|
|
|
2024-02-02 12:25:43 +00:00
|
|
|
if (!isHeadless || headless === 'true') {
|
2022-06-10 10:39:18 +00:00
|
|
|
// TODO: this test is partially blocked on crbug.com/1334119. Enable test once
|
|
|
|
// the upstream is fixed.
|
2023-01-13 17:03:21 +00:00
|
|
|
// TLDR: when we dispatch events to the frame the compositor might
|
2022-06-10 10:39:18 +00:00
|
|
|
// not be up-to-date yet resulting in a misclick (the iframe element
|
|
|
|
// becomes the event target instead of the content inside the iframe).
|
|
|
|
// The solution is to use InsertVisualCallback on the backend but that causes
|
|
|
|
// another issue that events cannot be dispatched to inactive tabs as the
|
|
|
|
// visual callback is never invoked.
|
|
|
|
// The old headless mode does not have this issue since it operates with
|
|
|
|
// special scheduling settings that keep even inactive tabs updating.
|
|
|
|
return;
|
|
|
|
}
|
2021-10-28 09:25:49 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
|
|
|
|
const frame = await framePromise;
|
|
|
|
await frame.evaluate(() => {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.id = 'test-button';
|
2022-01-17 06:32:52 +00:00
|
|
|
button.innerText = 'click';
|
|
|
|
button.onclick = () => {
|
|
|
|
button.id = 'clicked';
|
|
|
|
};
|
2021-10-28 09:25:49 +00:00
|
|
|
document.body.appendChild(button);
|
|
|
|
});
|
2022-01-17 06:32:52 +00:00
|
|
|
await page.evaluate(() => {
|
|
|
|
document.body.style.border = '150px solid black';
|
|
|
|
document.body.style.margin = '250px';
|
|
|
|
document.body.style.padding = '50px';
|
|
|
|
});
|
2022-06-22 13:25:44 +00:00
|
|
|
await frame.waitForSelector('#test-button', {visible: true});
|
2021-10-28 09:25:49 +00:00
|
|
|
await frame.click('#test-button');
|
2022-01-17 06:32:52 +00:00
|
|
|
await frame.waitForSelector('#clicked');
|
2021-10-28 09:25:49 +00:00
|
|
|
});
|
|
|
|
it('should report oopif frames', async () => {
|
2024-02-12 16:28:21 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
2022-06-22 13:25:44 +00:00
|
|
|
const frame = page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('/oopif.html');
|
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
2021-10-28 09:25:49 +00:00
|
|
|
await frame;
|
2024-02-12 16:28:21 +00:00
|
|
|
expect(await iframes(page)).toHaveLength(1);
|
2023-04-25 13:02:25 +00:00
|
|
|
expect(page.frames()).toHaveLength(2);
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2022-05-04 05:46:38 +00:00
|
|
|
|
|
|
|
it('should wait for inner OOPIFs', async () => {
|
2024-02-12 16:28:21 +00:00
|
|
|
const {server, page} = state;
|
2022-05-04 05:46:38 +00:00
|
|
|
await page.goto(`http://mainframe:${server.PORT}/main-frame.html`);
|
2022-06-22 13:25:44 +00:00
|
|
|
const frame2 = await page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('inner-frame2.html');
|
|
|
|
});
|
2024-02-12 16:28:21 +00:00
|
|
|
expect(await iframes(page)).toHaveLength(2);
|
2022-05-04 05:46:38 +00:00
|
|
|
expect(
|
2022-06-22 13:25:44 +00:00
|
|
|
page.frames().filter(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.isOOPFrame();
|
2023-04-25 13:02:25 +00:00
|
|
|
})
|
|
|
|
).toHaveLength(2);
|
2022-06-15 10:09:22 +00:00
|
|
|
expect(
|
|
|
|
await frame2.evaluate(() => {
|
|
|
|
return document.querySelectorAll('button').length;
|
|
|
|
})
|
2022-05-04 05:46:38 +00:00
|
|
|
).toStrictEqual(1);
|
|
|
|
});
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should load oopif iframes with subresources and request interception', async () => {
|
2024-02-12 16:28:21 +00:00
|
|
|
const {server, page} = state;
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2023-08-29 16:12:04 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('/oopif.html');
|
|
|
|
});
|
2022-06-22 13:25:44 +00:00
|
|
|
page.on('request', request => {
|
2023-08-29 16:12:04 +00:00
|
|
|
void request.continue();
|
|
|
|
});
|
|
|
|
await page.setRequestInterception(true);
|
|
|
|
const requestPromise = page.waitForRequest(request => {
|
|
|
|
return request.url().includes('requestFromOOPIF');
|
2022-06-15 10:09:22 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
2023-08-29 16:12:04 +00:00
|
|
|
const frame = await framePromise;
|
|
|
|
const request = await requestPromise;
|
2024-02-12 16:28:21 +00:00
|
|
|
expect(await iframes(page)).toHaveLength(1);
|
2023-08-29 16:12:04 +00:00
|
|
|
expect(request.frame()).toBe(frame);
|
2019-05-29 23:49:44 +00:00
|
|
|
});
|
2023-08-29 16:12:04 +00:00
|
|
|
|
2021-10-28 09:25:49 +00:00
|
|
|
it('should support frames within OOP iframes', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2021-10-28 09:25:49 +00:00
|
|
|
|
2022-06-22 13:25:44 +00:00
|
|
|
const oopIframePromise = page.waitForFrame(frame => {
|
2021-10-28 09:25:49 +00:00
|
|
|
return frame.url().endsWith('/oopif.html');
|
|
|
|
});
|
|
|
|
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
|
|
|
const oopIframe = await oopIframePromise;
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
oopIframe,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
|
2022-06-15 10:09:22 +00:00
|
|
|
const frame1 = oopIframe.childFrames()[0]!;
|
2021-10-28 09:25:49 +00:00
|
|
|
expect(frame1.url()).toMatch(/empty.html$/);
|
2023-04-25 13:02:25 +00:00
|
|
|
await navigateFrame(
|
2021-10-28 09:25:49 +00:00
|
|
|
oopIframe,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/oopif.html'
|
|
|
|
);
|
|
|
|
expect(frame1.url()).toMatch(/oopif.html$/);
|
|
|
|
await frame1.goto(
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/oopif.html#navigate-within-document',
|
2022-06-22 13:25:44 +00:00
|
|
|
{waitUntil: 'load'}
|
2021-10-28 09:25:49 +00:00
|
|
|
);
|
|
|
|
expect(frame1.url()).toMatch(/oopif.html#navigate-within-document$/);
|
2023-04-25 13:02:25 +00:00
|
|
|
await detachFrame(oopIframe, 'frame1');
|
2021-10-28 09:25:49 +00:00
|
|
|
expect(oopIframe.childFrames()).toHaveLength(0);
|
|
|
|
});
|
2022-01-17 06:32:52 +00:00
|
|
|
|
2022-01-17 13:19:43 +00:00
|
|
|
it('clickablePoint, boundingBox, boxModel should work for elements inside OOPIFs', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2022-01-17 06:32:52 +00:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2022-06-22 13:25:44 +00:00
|
|
|
const framePromise = page.waitForFrame(frame => {
|
2022-01-17 06:32:52 +00:00
|
|
|
return page.frames().indexOf(frame) === 1;
|
|
|
|
});
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2022-01-17 06:32:52 +00:00
|
|
|
page,
|
|
|
|
'frame1',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
const frame = await framePromise;
|
|
|
|
await page.evaluate(() => {
|
|
|
|
document.body.style.border = '50px solid black';
|
|
|
|
document.body.style.margin = '50px';
|
|
|
|
document.body.style.padding = '50px';
|
|
|
|
});
|
|
|
|
await frame.evaluate(() => {
|
|
|
|
const button = document.createElement('button');
|
|
|
|
button.id = 'test-button';
|
|
|
|
button.innerText = 'click';
|
|
|
|
document.body.appendChild(button);
|
|
|
|
});
|
2023-08-30 10:02:59 +00:00
|
|
|
using button = (await frame.waitForSelector('#test-button', {
|
2022-01-17 06:32:52 +00:00
|
|
|
visible: true,
|
2022-06-15 10:09:22 +00:00
|
|
|
}))!;
|
2022-01-17 06:32:52 +00:00
|
|
|
const result = await button.clickablePoint();
|
|
|
|
expect(result.x).toBeGreaterThan(150); // padding + margin + border left
|
|
|
|
expect(result.y).toBeGreaterThan(150); // padding + margin + border top
|
2022-06-15 10:09:22 +00:00
|
|
|
const resultBoxModel = (await button.boxModel())!;
|
2022-01-17 13:19:43 +00:00
|
|
|
for (const quad of [
|
|
|
|
resultBoxModel.content,
|
|
|
|
resultBoxModel.border,
|
|
|
|
resultBoxModel.margin,
|
|
|
|
resultBoxModel.padding,
|
|
|
|
]) {
|
|
|
|
for (const part of quad) {
|
|
|
|
expect(part.x).toBeGreaterThan(150); // padding + margin + border left
|
|
|
|
expect(part.y).toBeGreaterThan(150); // padding + margin + border top
|
|
|
|
}
|
|
|
|
}
|
2022-06-15 10:09:22 +00:00
|
|
|
const resultBoundingBox = (await button.boundingBox())!;
|
2022-01-17 13:19:43 +00:00
|
|
|
expect(resultBoundingBox.x).toBeGreaterThan(150); // padding + margin + border left
|
|
|
|
expect(resultBoundingBox.y).toBeGreaterThan(150); // padding + margin + border top
|
2022-01-17 06:32:52 +00:00
|
|
|
});
|
2022-01-17 07:00:00 +00:00
|
|
|
|
|
|
|
it('should detect existing OOPIFs when Puppeteer connects to an existing page', async () => {
|
2024-02-12 16:28:21 +00:00
|
|
|
const {server, puppeteer, page} = state;
|
2022-01-17 07:00:00 +00:00
|
|
|
|
2022-06-22 13:25:44 +00:00
|
|
|
const frame = page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('/oopif.html');
|
|
|
|
});
|
2022-01-17 07:00:00 +00:00
|
|
|
await page.goto(server.PREFIX + '/dynamic-oopif.html');
|
|
|
|
await frame;
|
2024-02-12 16:28:21 +00:00
|
|
|
expect(await iframes(page)).toHaveLength(1);
|
2023-04-25 13:02:25 +00:00
|
|
|
expect(page.frames()).toHaveLength(2);
|
2022-01-17 07:00:00 +00:00
|
|
|
|
|
|
|
const browserURL = 'http://127.0.0.1:21222';
|
2024-05-02 07:22:06 +00:00
|
|
|
using browser1 = await puppeteer.connect({browserURL});
|
2022-06-22 13:25:44 +00:00
|
|
|
const target = await browser1.waitForTarget(target => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return target.url().endsWith('dynamic-oopif.html');
|
|
|
|
});
|
2022-01-17 07:00:00 +00:00
|
|
|
await target.page();
|
2023-11-30 14:27:49 +00:00
|
|
|
await browser1.disconnect();
|
2022-01-17 07:00:00 +00:00
|
|
|
});
|
2022-07-25 09:20:38 +00:00
|
|
|
|
2022-09-08 10:32:39 +00:00
|
|
|
it('should support lazy OOP frames', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2022-05-17 12:15:44 +00:00
|
|
|
|
|
|
|
await page.goto(server.PREFIX + '/lazy-oopif-frame.html');
|
2022-06-22 13:25:44 +00:00
|
|
|
await page.setViewport({width: 1000, height: 1000});
|
2022-05-17 12:15:44 +00:00
|
|
|
|
2022-06-15 10:09:22 +00:00
|
|
|
expect(
|
2022-06-22 13:25:44 +00:00
|
|
|
page.frames().map(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame._hasStartedLoading;
|
|
|
|
})
|
|
|
|
).toEqual([true, true, false]);
|
2022-05-17 12:15:44 +00:00
|
|
|
});
|
2022-04-07 13:05:36 +00:00
|
|
|
|
2024-05-02 11:27:18 +00:00
|
|
|
it('should exposeFunction on a page with a PDF viewer', async () => {
|
|
|
|
const {page, server} = state;
|
|
|
|
|
|
|
|
await page.goto(server.PREFIX + '/pdf-viewer.html', {
|
|
|
|
waitUntil: 'networkidle2',
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.exposeFunction('test', () => {
|
|
|
|
console.log('test');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should evaluate on a page with a PDF viewer', async () => {
|
|
|
|
const {page, server} = state;
|
|
|
|
|
|
|
|
await page.goto(server.PREFIX + '/pdf-viewer.html', {
|
|
|
|
waitUntil: 'networkidle2',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await Promise.all(
|
|
|
|
page.frames().map(async frame => {
|
|
|
|
return await frame.evaluate(() => {
|
|
|
|
return window.location.pathname;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
)
|
|
|
|
).toEqual([
|
|
|
|
'/pdf-viewer.html',
|
|
|
|
'/sample.pdf',
|
|
|
|
'/index.html',
|
|
|
|
'/sample.pdf',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2022-04-07 13:05:36 +00:00
|
|
|
describe('waitForFrame', () => {
|
|
|
|
it('should resolve immediately if the frame already exists', async () => {
|
2023-07-03 12:01:29 +00:00
|
|
|
const {server, page} = state;
|
2022-04-07 13:05:36 +00:00
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2023-04-25 13:02:25 +00:00
|
|
|
await attachFrame(
|
2022-04-07 13:05:36 +00:00
|
|
|
page,
|
|
|
|
'frame2',
|
|
|
|
server.CROSS_PROCESS_PREFIX + '/empty.html'
|
|
|
|
);
|
|
|
|
|
2022-06-22 13:25:44 +00:00
|
|
|
await page.waitForFrame(frame => {
|
2022-06-15 10:09:22 +00:00
|
|
|
return frame.url().endsWith('/empty.html');
|
|
|
|
});
|
2022-04-07 13:05:36 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-04 06:51:47 +00:00
|
|
|
|
|
|
|
it('should report google.com frame', async () => {
|
|
|
|
const {server, page} = state;
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.setRequestInterception(true);
|
2024-01-11 14:26:02 +00:00
|
|
|
page.on('request', r => {
|
2024-01-04 06:51:47 +00:00
|
|
|
return r.respond({body: 'YO, GOOGLE.COM'});
|
|
|
|
});
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const frame = document.createElement('iframe');
|
|
|
|
frame.setAttribute('src', 'https://google.com/');
|
|
|
|
document.body.appendChild(frame);
|
|
|
|
return new Promise(x => {
|
|
|
|
return (frame.onload = x);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
await page.waitForSelector('iframe[src="https://google.com/"]');
|
|
|
|
const urls = page
|
|
|
|
.frames()
|
2024-01-11 14:26:02 +00:00
|
|
|
.map(frame => {
|
2024-01-04 06:51:47 +00:00
|
|
|
return frame.url();
|
|
|
|
})
|
|
|
|
.sort();
|
|
|
|
expect(urls).toEqual([server.EMPTY_PAGE, 'https://google.com/']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should expose events within OOPIFs', async () => {
|
|
|
|
const {server, page} = state;
|
|
|
|
|
|
|
|
// Setup our session listeners to observe OOPIF activity.
|
2024-02-08 12:56:58 +00:00
|
|
|
const session = await page.createCDPSession();
|
2024-01-11 14:26:02 +00:00
|
|
|
const networkEvents: string[] = [];
|
|
|
|
const otherSessions: CDPSession[] = [];
|
2024-01-04 06:51:47 +00:00
|
|
|
await session.send('Target.setAutoAttach', {
|
|
|
|
autoAttach: true,
|
|
|
|
flatten: true,
|
|
|
|
waitForDebuggerOnStart: true,
|
|
|
|
});
|
2024-01-11 14:26:02 +00:00
|
|
|
session.on(CDPSessionEvent.SessionAttached, async session => {
|
|
|
|
otherSessions.push(session);
|
|
|
|
|
|
|
|
session.on('Network.requestWillBeSent', params => {
|
|
|
|
return networkEvents.push(params.request.url);
|
|
|
|
});
|
|
|
|
await session.send('Network.enable');
|
|
|
|
await session.send('Runtime.runIfWaitingForDebugger');
|
|
|
|
});
|
2024-01-04 06:51:47 +00:00
|
|
|
|
|
|
|
// Navigate to the empty page and add an OOPIF iframe with at least one request.
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(
|
|
|
|
(frameUrl: string) => {
|
|
|
|
const frame = document.createElement('iframe');
|
|
|
|
frame.setAttribute('src', frameUrl);
|
|
|
|
document.body.appendChild(frame);
|
|
|
|
return new Promise((x, y) => {
|
|
|
|
frame.onload = x;
|
|
|
|
frame.onerror = y;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
server.PREFIX.replace('localhost', 'oopifdomain') + '/one-style.html'
|
|
|
|
);
|
|
|
|
await page.waitForSelector('iframe');
|
|
|
|
|
|
|
|
// Ensure we found the iframe session.
|
|
|
|
expect(otherSessions).toHaveLength(1);
|
|
|
|
|
|
|
|
// Resume the iframe and trigger another request.
|
|
|
|
const iframeSession = otherSessions[0]!;
|
|
|
|
await iframeSession.send('Runtime.evaluate', {
|
|
|
|
expression: `fetch('/fetch')`,
|
|
|
|
awaitPromise: true,
|
|
|
|
});
|
|
|
|
|
2024-01-11 14:26:02 +00:00
|
|
|
expect(networkEvents).toContain(`http://oopifdomain:${server.PORT}/fetch`);
|
2024-01-04 06:51:47 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2019-06-04 18:03:15 +00:00
|
|
|
|
2024-02-12 16:28:21 +00:00
|
|
|
async function iframes(page: Page) {
|
|
|
|
const iframes = await Promise.all(
|
|
|
|
page.frames().map(async frame => {
|
|
|
|
return await frame.frameElement();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return iframes.filter(frame => {
|
|
|
|
return frame !== null;
|
2022-06-15 10:09:22 +00:00
|
|
|
});
|
2019-06-04 18:03:15 +00:00
|
|
|
}
|