前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Playwright 源码 启动 Chromium 的命令

Playwright 源码 启动 Chromium 的命令

原创
作者头像
华健课堂
修改2024-10-29 14:16:24
修改2024-10-29 14:16:24
1270
举报

问:Playwright 无声无息地启动了 Chromium,到底底层执行了个啥子?

带着问题,开启探险之旅!!!👇👇👇

1. npm init 创建 npm 项目;

2. npm install playwright 安装 playwright 依赖;

3. 创建 demo.js,添加如下代码:

代码语言:javascript
复制
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();  
  const page = await browser.newPage();
  await page.goto('http://localhost/');
  await browser.close();
})();

4. node_modules\playwright-core\lib\utils\processLauncher.jsasync function launchProcess() 添加一行调试代码;

代码语言:javascript
复制
async function launchProcess(options) {
  // ...
  const spawnedProcess = childProcess.spawn(options.command, options.args || [], spawnOptions);
  // 调试代码
  console.log(`${options.command} ${options.args.join(' ')}`);
  // ... 
}     

5. 新添加的那行代码左侧,添加断点,运行并调试 demo.js

答:Playwright 启动 Chromium 执行的命令为 C:\Users\zhouhuajian\AppData\Local\ms-playwright\chromium-1140\chrome-win\chrome.exe --disable-field-trial-config --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding,ThirdPartyStoragePartitioning,LensOverlay,PlzDedicatedWorker --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --headless=old --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=C:\Users\ZHOUHU~1\AppData\Local\Temp\playwright_chromiumdev_profile-XXXXXXd9ksml --remote-debugging-pipe --no-startup-window

噢耶!你答对了!100分! ✌️✌️✌️


Huajianketang's proud of you.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档