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

[Question] Why is 'setDownloadBehavior' required for connect_over_cdp? Any workaround? #30383

Closed
1 task done
LFMM-33 opened this issue Apr 16, 2024 · 7 comments
Closed
1 task done

Comments

@LFMM-33
Copy link

LFMM-33 commented Apr 16, 2024

Hello to all,

Sorry to bother here with a question. I added the same question in Discord but after a week, noone has answered so I'm trying luck here. Sorry for the spam.

I'm working on developing tests E2E for a web desktop application that uses Qt as its base for UI. The Qt version we are deploying uses Chromium v108.0.5359.71 as browser and we've successfully developed tests using ChromeDriver+Selenium but we are interested on transitioning to Playwright.

The issue we are having, also stated in the following comment in Github (#10927 (comment)) is that for some reason we aren't able to connect over CDP because the 'Browser.setDownloadBehavior' request is failing (file node_modules/playwright-core/lib/server/chromium/crBrowser.js -> _initialize function)

if (this._browser.options.name !== 'electron' && this._browser.options.name !== 'clank' && this._options.acceptDownloads !== 'internal-browser-default') {
      promises.push(this._browser._session.send('Browser.setDownloadBehavior', {
        behavior: this._options.acceptDownloads === 'accept' ? 'allowAndName' : 'deny',
        browserContextId: this._browserContextId,
        downloadPath: this._browser.options.downloadsPath,
        eventsEnabled: true
      }));
    }

I enter this condition because our browser seems to have this._options.acceptDownloads = 'accept'. Before, if you see the comment linked above, the only restrictions were electron and clank.

If I comment this CDP request, Playwright is able to connect and my tests work as expected.

So, my question would be why is this a requirement and if anyone knows any workaround / a way to set Chromium browser's "acceptDownloads" option to the expected value "internal-browser-default" so I can overpass this?

Thank you for reading

  • I understand
@mxschmitt
Copy link
Member

Filed upstream bug: chromiumembedded/cef#3684
Filed upstream PR: https://bitbucket.org/chromiumembedded/cef/pull-requests/748

@dgozman
Copy link
Contributor

dgozman commented Apr 23, 2024

Closing in favor of chromiumembedded/cef#3684, since there is no action item on Playwright side.

@dgozman dgozman closed this as completed Apr 23, 2024
@mxschmitt
Copy link
Member

@LFMM-33 would that work for you? chromiumembedded/cef#3684 (comment)

Since the CEF Alloy mode is deprecated and gets removed soon the solution above seems to work as of today.

@LFMM-33
Copy link
Author

LFMM-33 commented May 30, 2024

Good morning,

@mxschmitt My apologies for the late response, the project got delayed due to other priorities.

It still keeps not working for me... I've added this line process.env.PW_CHROMIUM_ATTACH_TO_OTHER = '1'; after the import and launched the chromium browser with both "--enable-chrome-runtime" and "--use-views" flags (also together) as suggested in the comments in here but nothing seems to work.

I keep receiving the same error message:

Error: browserType.connectOverCDP: Protocol error (Browser.setDownloadBehavior): Browser context management is not supported.
    Call log:
      - <ws preparing> retrieving websocket url from http://localhost:9222
      - <ws connecting> ws://localhost:9222/devtools/browser/5d138cbc-fef3-459a-9950-e0535e27b1f6
      - <ws connected> ws://localhost:9222/devtools/browser/5d138cbc-fef3-459a-9950-e0535e27b1f6

I leave my code here in case you spot anything weird:

import { test as base } from '@playwright/test';

const qa_check = process.env.QA_BUILD;
process.env.PW_CHROMIUM_ATTACH_TO_OTHER = '1';

function getFixture() {	
	let test; 
	if (qa_check !== undefined) {
		test = base.extend({
			browser: async ({ playwright }, use) => {
				const browser = await playwright.chromium.connectOverCDP("http://localhost:9222"); # Failing here
				await use(browser);
				await browser.close();
			},
			context: async ({ browser }, use) => {
				const context = browser.contexts()[0];
				await use(context);
			},
			page: async ({ context }, use) => {
				const page = context.pages()[0];
                                 await use(page);
			},
		});
	} else {
		test = base;
	}
	return test;
}

export const test = getFixture();

I also do not know what "CEF Alloy mode" is to me honest, netiher how I could give you more info on my situation. Might be my Chromium version? Maybe it's too "old" for these features though the flags are been accepted by the broswer (no error was raised) but it's definetly not working :(

@mxschmitt
Copy link
Member

@LFMM-33 CEF can be launched in two modes. Alloy which is deprecated and gets removed from CEF soon and native Chrome mode. The native Chrome mode. Depending on your implementation, it might be --enable-chrome-runtime or CefSettings.chrome_runtime = true.

And yes, it requires a recent CEF I think.

@LFMM-33
Copy link
Author

LFMM-33 commented May 30, 2024

@mxschmitt Thank you for the clarification. I'll look into it with a C++ dev.

Any indication / any check that could confirm if "Chrome runtime" is indeed enabled?
Anything I could check in the Devtools? Just looking to get more info.

@mxschmitt
Copy link
Member

I'm unfortunately not very familiar with CEF, this might be helpful: chromiumembedded/cef#3685

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

No branches or pull requests

4 participants