What is the Puppeteer equivalent of window.document.referrer?
Richard W
The Puppeteer equivalent ofwindow.document.referrer ispage.referrer(). Here's a detailed explanation:
1. Launching a new browser instance and creating a new page:
1
2
3
4
5
6
7
8
9
10
11
12
13
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Perform actions with the page here
// Close the browser
await browser.close();
})();
This code sets up a basic Puppeteer script. It launches a new headless browser instance and creates a new page to work with.
2. Getting the referrer usingpage.referrer():
To get the referrer value in Puppeteer, you can use thepage.referrer() method.
In this example,page.referrer() is called to retrieve the referrer value of the current page. The returned value represents the URL of the referring page.
By utilizingpage.referrer(), you can access the referrer value of a page in Puppeteer. This can be useful for tracking the source or previous page that led to the current page during web scraping, analytics, or other data gathering tasks.