我想知道是否可以有一个 .js 文件来打开浏览器实例、创建新页面/选项卡登录到网站(使用用户名/密码)并保持空闲状态。
在第二个 .js 文件中使用文件一个浏览器实例及其页面。
1.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox'],
ignoreDefaultArgs: ["--hide-scrollbars"]
});
const page = await browser.newPage();
const response = await page.goto('https://google.com');
console.log('Browser open in the background (headless)!');
//await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
2.js
const puppeteer = require('puppeteer');
(async () => {
// instructions on browser instance/page from 1.js ...
})();
Run Code Online (Sandbox Code Playgroud)