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 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
26 changes: 15 additions & 11 deletions clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ async function getPageFromConnection(connection) {
'chrome',
pptrConnection,
[] /* contextIds */,
false /* ignoreHTTPSErrors */,
undefined /* defaultViewport */,
undefined /* process */,
undefined /* closeCallback */,
// @ts-expect-error internal property
targetInfo => targetInfo._targetId === mainTargetInfo.targetId
false /* ignoreHTTPSErrors */
);

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.
const targetPromise = browser.waitForTarget(async (target) => {
const page = await target.page();
if (page && page.mainFrame()._id === frameTree.frame.id) return true;
return false;
});
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const page = await Promise.race([
targetPromise.then(target => target.page()),
new Promise((_, reject) => {
setTimeout(() => reject(new Error('Could not find relevant puppeteer page')), 5000);
}),
]);
return page;
}

Expand Down
Loading