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.
1 2 3 4 5
const referrer = await page.referrer(); console.log('Referrer:', referrer);
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.
Similar Questions
What is the Puppeteer equivalent of window.document.title?
What is the Puppeteer equivalent of window.open()?
What is the Puppeteer equivalent of document.readyState?
What is the Puppeteer equivalent of window.alert()?
What is the Puppeteer equivalent of window.location?
What is the Puppeteer equivalent of window.history?
What is the Puppeteer equivalent of window.performance?
What is the Puppeteer equivalent of window.location.reload()?
What is the Puppeteer equivalent of window.localStorage?
What is the Puppeteer equivalent of window.scrollTo()?
What is the Puppeteer equivalent of document.querySelector()?
What is the Puppeteer equivalent of window.sessionStorage?
What is the Puppeteer equivalent of document.querySelectorAll()?
What is the Puppeteer API method to focus an element on the page?
What is the Puppeteer API method to close a browser tab?
How do I handle dynamically generated content in Puppeteer?
What is the Puppeteer method to reload a page?
What is the best way to handle pop-up dialogs in Puppeteer?