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

clients(lr): modify puppeteer connector to work with new tab targets #15674

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Changes from 1 commit
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
33 changes: 26 additions & 7 deletions clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,34 @@ async function getPageFromConnection(connection) {
undefined /* defaultViewport */,
undefined /* process */,
undefined /* closeCallback */,
// @ts-expect-error internal property
targetInfo => targetInfo._targetId === mainTargetInfo.targetId
// eslint-disable-next-line no-unused-vars
targetInfo => true
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
);

const pages = await browser.pages();
const page = pages.find(p => p.mainFrame()._id === frameTree.frame.id);
if (!page) throw new Error('Could not find relevant puppeteer page');

// @ts-expect-error Page has a slightly different type when importing the browser module directly.
// We should be able to find the relevant page instantly, but just in case
// the relevant tab target comes a bit delayed, check every time a new
// target is seen.
/** @type {(value: any) => void} */
let resolve;
/** @type {(value: Error) => void} */
let reject;
const promise = new Promise((resolve_, reject_) => {
resolve = resolve_;
reject = reject_;
});
browser.waitForTarget(async () => {
const pages = await browser.pages();
const page = pages.find(p => p.mainFrame()._id === frameTree.frame.id);
if (page) {
resolve(page);
return true;
}
return false;
});
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const timeoutHandle = setTimeout(() =>
reject(new Error('Could not find relevant puppeteer page')), 5000);
const page = await promise;
clearTimeout(timeoutHandle);
return page;
}

Expand Down
Loading