问:Playwright 无声无息地启动了 Chromium,到底底层执行了个啥子?
带着问题,开启探险之旅!!!👇👇👇
1. npm init
创建 npm 项目;
2. npm install playwright
安装 playwright
依赖;
3. 创建 demo.js
,添加如下代码:
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.js
的 async function launchProcess()
添加一行调试代码;
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.