xvrh / puppeteer-dart

A Dart library to automate the Chrome browser over the DevTools Protocol. This is a port of the Puppeteer API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mac app:

SevenWangMr opened this issue · comments

I built a widget on FlutterUI and launched a class through the widget. In the class, there is an instance method that initializes the puppeteer.launch. then got error

flutter: 2024-02-05 15:10:28.352396:puppeteer.launcher:1
INFO: Start .local-chrome/119.0.6045.105/chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing with [--allow-pre-commit-input, --disable-background-networking, --disable-background-timer-throttling, --disable-backgrounding-occluded-windows, --disable-breakpad, --disable-client-side-phishing-detection, --disable-component-extensions-with-background-pages, --disable-component-update, --disable-default-apps, --disable-dev-shm-usage, --disable-extensions, --disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints, --disable-hang-monitor, --disable-ipc-flooding-protection, --disable-popup-blocking, --disable-prompt-on-repost, --disable-renderer-backgrounding, --disable-search-engine-choice-screen, --disable-sync, --enable-automation, --enable-blink-features=IdleDetection, --enable-features=NetworkServiceInProcess2, --export-tagged-pdf, --force-color-profile=srgb, --metrics-recording-only, --no-first-run, --password-store=basic, --use-mock-keychain, --no-sandbox, about:blank, --disable-setuid-sandbox, --remote-debugging-port=0, --user-data-dir=/var/folders/zf/mdsyzmyx5n57b3m447v4_f6w0000gn/T/com.example.mediaClient/puppeteer_dev_profile-N7VFro]
flutter: 2024-02-05 15:10:28.374666:stream:2
SHOUT: 2024-02-05 15:10:28.372952:ProcessException: Operation not permitted
Command: .local-chrome/119.0.6045.105/chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing --allow-pre-commit-input --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-sync --enable-automation --enable-blink-features=IdleDetection --enable-features=NetworkServiceInProcess2 --export-tagged-pdf --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-sandbox about:blank --disable-setuid-sandbox --remote-debugging-port=0 --user-data-dir=/var/folders/zf/mdsyzmyx5n57b3m447v4_f6w0000gn/T/com.example.mediaClient/puppeteer_dev_profile-N7VFro
#0 _ProcessImpl._start (dart:io-patch/process_patch.dart:402:33)
#1 Process.start (dart:io-patch/process_patch.dart:38:20)
#2 Puppeteer.launch (package:puppeteer/src/puppeteer.dart:175:39)

#3 BaseWebView2.createPage (package:media_client/service/base_webview2.dart:30:19)

I think you should opt-out of sandbox mode in the xcode project.

Something like that in your Profile.entitlements:

<key>com.apple.security.app-sandbox</key>
<false/>

I triggered the pusheter initialization through a button, and the above error disappeared, but error changed to

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Websocket url not found
#0 _waitForWebSocketUrl (package:puppeteer/src/puppeteer.dart:345:3)

#1 Puppeteer.launch. (package:puppeteer/src/puppeteer.dart:192:24)

#2 Future.timeout. (dart:async/future_impl.dart:948:15)

#3 Puppeteer.launch (package:puppeteer/src/puppeteer.dart:191:24)

#4 BaseWebView2.createPage (package:media_client/service/base_webview2.dart:24:19)

#5 _MyHomePageState.build. (package:media_client/pages/test_page.dart:70:15)

com.apple.security.app-sandbox

I had modified the plist file in macos.

var browser = await puppeteer.launch(
devTools: false,
executablePath: BrowserPath.chrome,
noSandboxFlag: true,
args: puppeteer.defaultArgs(),
headless: false,
userDataDir: "profile-folder"
);
this is my code