summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/examples/cross-browser.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /remote/test/puppeteer/examples/cross-browser.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/examples/cross-browser.js')
-rw-r--r--remote/test/puppeteer/examples/cross-browser.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/remote/test/puppeteer/examples/cross-browser.js b/remote/test/puppeteer/examples/cross-browser.js
new file mode 100644
index 0000000000..5027afb875
--- /dev/null
+++ b/remote/test/puppeteer/examples/cross-browser.js
@@ -0,0 +1,48 @@
+const puppeteer = require('puppeteer');
+
+/**
+ * To have Puppeteer fetch a Firefox binary for you, first run:
+ *
+ * PUPPETEER_PRODUCT=firefox npm install
+ *
+ * To get additional logging about which browser binary is executed,
+ * run this example as:
+ *
+ * DEBUG=puppeteer:launcher NODE_PATH=../ node examples/cross-browser.js
+ *
+ * You can set a custom binary with the `executablePath` launcher option.
+ *
+ *
+ */
+
+const firefoxOptions = {
+ product: 'firefox',
+ extraPrefsFirefox: {
+ // Enable additional Firefox logging from its protocol implementation
+ // 'remote.log.level': 'Trace',
+ },
+ // Make browser logs visible
+ dumpio: true,
+};
+
+(async () => {
+ const browser = await puppeteer.launch(firefoxOptions);
+
+ const page = await browser.newPage();
+ console.log(await browser.version());
+
+ await page.goto('https://news.ycombinator.com/');
+
+ // Extract articles from the page.
+ const resultsSelector = '.titleline > a';
+ const links = await page.evaluate(resultsSelector => {
+ const anchors = Array.from(document.querySelectorAll(resultsSelector));
+ return anchors.map(anchor => {
+ const title = anchor.textContent.trim();
+ return `${title} - ${anchor.href}`;
+ });
+ }, resultsSelector);
+ console.log(links.join('\n'));
+
+ await browser.close();
+})();