Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Firefox headless #598

Open
thbley opened this issue Jan 14, 2024 · 0 comments
Open

Support for Firefox headless #598

thbley opened this issue Jan 14, 2024 · 0 comments

Comments

@thbley
Copy link

thbley commented Jan 14, 2024

It would be nice if Firefox would be supported as well.
(my initial tests with MS Edge 120 on Linux were successful without further patches)

From "https://firefox-source-docs.mozilla.org/remote/index.html#remote-protocol-cdp-header":
Firefox implements a subset of the Chrome DevTools Protocol (CDP) in order to support third party automation tools such as puppeteer.

E.g. I patched the handshake:

GET /devtools/browser/ef8d2af9-3280-42f0-b812-c49b8dbaca19 HTTP/1.1
host: 127.0.0.1:9222
upgrade: websocket
connection: Upgrade
sec-websocket-key: 4InfZD3P8p82pb4iQ1wLKQ==
origin: http://127.0.0.1
sec-websocket-version: 13

HTTP/1.1 400 Bad Request
Server: httpd.js
Content-Type: text/plain
Content-Length: 66

with:

   protected function getDefaultRequestHeaders(
       string $host,
       string $key,
       string $origin
   ): array {
       return [
           self::HEADER_HOST => $host,
           self::HEADER_UPGRADE => self::UPGRADE_VALUE,
           self::HEADER_CONNECTION => self::CONNECTION_VALUE,
           self::HEADER_KEY => $key,
           // self::HEADER_ORIGIN => $origin,
           self::HEADER_VERSION => (string) $this->getVersion(),
       ];
   }

I also patched Frame::__construct:

TypeError: HeadlessChromium\Frame::getLatestLoaderId(): Return value must be of type string, null returned
  │
  │ /home/tb/code/php_frameworkless/tasks_be/tests/vendor/chrome-php/chrome/src/Frame.php:98
  │ /home/tb/code/php_frameworkless/tasks_be/tests/vendor/chrome-php/chrome/src/PageUtils/PageNavigation.php:84
  │ /home/tb/code/php_frameworkless/tasks_be/tests/vendor/chrome-php/chrome/src/Page.php:216

with:

   public function __construct(array $frameData)
   {
       $this->frameData = $frameData;
       $this->latestLoaderId = $frameData['loaderId'] ?? 0;
       $this->frameId = $frameData['id'];
   }

Versions:
Firefox 121.0
chrome-php/chrome v1.10.0

Headless Firefox also requires to change 2 preferences to work with ChromeDP: https://firefox-source-docs.mozilla.org/remote/cdp/RequiredPreferences.html

Reference for startup parameters and setting initial preferences from puppeteer:

Firefox: https://github.com/puppeteer/puppeteer/blob/a87a03587949406dfda22377c48a22f915c760ef/packages/puppeteer-core/src/node/FirefoxLauncher.ts
Chrome: https://github.com/puppeteer/puppeteer/blob/a87a03587949406dfda22377c48a22f915c760ef/packages/puppeteer-core/src/node/ChromeLauncher.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant