2024-05-16 15:20:02 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2024 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
connect,
|
|
|
|
ExtensionTransport,
|
|
|
|
} from 'puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js';
|
|
|
|
|
|
|
|
globalThis.testConnect = async url => {
|
|
|
|
const tab = await chrome.tabs.create({
|
|
|
|
url,
|
|
|
|
});
|
2024-05-21 10:41:15 +00:00
|
|
|
|
|
|
|
// Wait for the new tab to load before connecting.
|
|
|
|
await new Promise(resolve => {
|
|
|
|
function listener(tabId, changeInfo) {
|
|
|
|
if (tabId === tab.id && changeInfo.status === 'complete') {
|
|
|
|
chrome.tabs.onUpdated.removeListener(listener);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chrome.tabs.onUpdated.addListener(listener);
|
|
|
|
});
|
|
|
|
|
2024-05-16 15:20:02 +00:00
|
|
|
const browser = await connect({
|
|
|
|
transport: await ExtensionTransport.connectTab(tab.id),
|
|
|
|
});
|
|
|
|
const [page] = await browser.pages();
|
2024-05-21 10:41:15 +00:00
|
|
|
const title = await page.evaluate(() => {
|
|
|
|
return document.title;
|
|
|
|
});
|
|
|
|
await browser.disconnect();
|
|
|
|
return title;
|
2024-05-16 15:20:02 +00:00
|
|
|
};
|