Reputation: 4188
Is there a way to reply to Chrome's notifications using puppeteer? I've tried disabling the notifications (I guess then it would just select yes by default?), but it didn't help:
const browser = await puppeteer.launch({headless: false, slowMo: 250, args: ["--disable-notifications"]});
Upvotes: 8
Views: 12496
Reputation: 3037
Make sure that the website whose notifications you want overridden does not redirect to a subdomain because then overridePermissions would not work straight away without calling it with the redirected url as well.
Upvotes: 0
Reputation: 997
Example: For closing notification pop up (puppeteer)
const puppeteer = require("puppeteer");
const website = "https://facebook.com/";
puppeteer
.launch({ headless: false })
.then(async (browser) => {
const page = await browser.newPage();
await page.goto(website);
const context = browser.defaultBrowserContext();
context.overridePermissions(website, ["notifications"]);
})
.catch(console.log);
Upvotes: 0
Reputation: 121
You just have to pass args
Example:
args: [
"--disable-notifications"
]
Upvotes: 10
Reputation:
Yes you can overide notifications as @splintor said. This is the code that would, for example, disable the Allow Notifications popup when logging into facebook.
let crawl = async function(){
let browser = await puppeteer.launch({ headless:false });
const context = browser.defaultBrowserContext();
// URL An array of permissions
context.overridePermissions("https://www.facebook.com", ["geolocation", "notifications"]);
let page = await browser.newPage();
await page.goto("https://www.facebook.com");
await page.type("#email", process.argv[2]);
await page.type("#pass", process.argv[3]);
await page.click("#u_0_2");
await page.waitFor(1000);
await page.waitForSelector("#pagelet_composer");
let content2 = await page.$$("#pagelet_composer");
console.log(content2); // .$$ An array containing elementHandles .$ would return 1 elementHandle
}
crawl();
Upvotes: 11
Reputation: 10154
Check ovverridePermissions, which was added in Puppeteer v1.8.0.
Upvotes: 3