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

Implement CefDevToolsManagerDelegate::GetDefaultBrowserContext for CDP cookie management #3684

Closed
mxschmitt opened this issue Apr 17, 2024 · 5 comments
Labels
bug Bug report

Comments

@mxschmitt
Copy link

Describe the bug

Currently CefDevToolsManagerDelegate::GetDefaultBrowserContext is not implemented, this causes the following CDP calls to fail:

  • Storage.{get|set|clear}Cookies
  • Browser.setDownloadBehavior

When implementing the method like done in Electron, things will start working: electron/electron#41738. This also makes it then compatible with Playwright.

There was a quite popular feature request on our side about connecting to CEF instances from Playwright: microsoft/playwright#10927

To Reproduce
Steps to reproduce the behavior:

  1. mkdir repro && cd repro && npm init -y && npm install playwright
  2. Create the test.mjs file
  3. node test.mjs
import { chromium } from 'playwright';

(async () => {
  const browser = await chromium.connectOverCDP('http://localhost:1234');

  console.log(browser.contexts().length);
  console.log(browser.contexts()[0].pages().length);

  const page = browser.contexts()[0].pages()[0];
  await page.goto('https://facebook.com');
  console.log(await page.context().cookies());

  await browser.close();
})();

It throws with Browser context management not supported from here.

Expected behavior

CDP calls work.

Screenshots

N/A

Versions (please complete the following information):

  • OS: macOS 14.2-arm64
  • CEF Version: tip-of-tree/master

Additional context

Does the problem reproduce with the cefclient or cefsimple sample application at the same version?

Yes

Does the problem reproduce with Google Chrome at the same version?

No

Add any other context about the problem here.

I'm currently working on a fix.

@magreenblatt
Copy link
Collaborator

@magreenblatt
Copy link
Collaborator

Given that this API should already work with the CEF Chrome bootstrap (same code as Google Chrome), and that the CEF Alloy bootstrap will be deleted in a few months (see #3685), I think we can just leave this unimplemented for Alloy and recommend that users start migrating to Chrome.

@magreenblatt magreenblatt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2024
@mxschmitt
Copy link
Author

Sounds good! Is there an easy way of trying out the new CEF Chrome bootstrap mode? cefclient / sefsimple is only using the alloy mode?

@magreenblatt
Copy link
Collaborator

Is there an easy way of trying out the new CEF Chrome bootstrap mode?

Yes, just add the --enable-chrome-runtime command-line flag to cefclient or cefsimple. If using cefsimple, also add --use-views.

@mxschmitt
Copy link
Author

Awesome, just tried it out and it works out of the box. For reference:

// @ts-check
// Requires: './cefclient --remote-debugging-port=1235 --url=about:blank --enable-chrome-runtime
import { chromium } from 'playwright';

process.env.PW_CHROMIUM_ATTACH_TO_OTHER = '1';

(async () => {
  const browser = await chromium.connectOverCDP('http://localhost:1235');
  const defaultContext = browser.contexts()[0];
  const defaultPage = defaultContext.pages()[0];
  await defaultPage.goto('http://example.com');

  console.log(await defaultPage.title());
  console.log(defaultPage.url());

  await defaultContext.close();
  await browser.close();
})();

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

No branches or pull requests

2 participants