gpt4 book ai didi

javascript - Puppeteer:关闭地理定位权限请求

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:39:39 26 4
gpt4 key购买 nike

如何使用 Puppeteer 关闭 Chrome 的地理定位权限请求?我把 page.on 放在各处,并尝试使用 confirmdialogalertprompt 。我还阅读了以下链接,但找不到解决方案:

我的脚本:

console.log("\nProcess Started");
//sample webpage
let webPage = "https://www.mta.org.nz/find-an-mta/?location=us";

const puppeteer = require("puppeteer");

async function main() {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.setViewport({
width: 1600,
height: 900
});

try {
await page.goto(webPage);
await page.waitForSelector("body");
await console.log("Loaded: " + webPage);
} catch (err) {
console.log("Error: " + webPage + "\n" + err);
}

await page.waitFor(10000);

browser.close();
await console.log("Process Ended \n");
};
main();

最佳答案

// page.setGeolocation(options)

const context = browser.defaultBrowserContext();
await context.overridePermissions(url, ['geolocation']);

https://pptr.dev/#?product=Puppeteer&version=v1.18.1&show=api-browsercontextoverridepermissionsorigin-permissions

关于javascript - Puppeteer:关闭地理定位权限请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51229360/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com