Skip to content

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

Closed

Description

@LFMM-33

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

Activity

  1. mxschmitt commented on Apr 18, 2024

    @mxschmitt
    Contributor
  2. dgozman commented on Apr 23, 2024

    @dgozman
    Collaborator

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

  3. mxschmitt commented on Apr 24, 2024

    @mxschmitt
    Contributor

    LFMM (@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.

  4. LFMM-33 commented on May 30, 2024

    @LFMM-33
    Author

    Good morning,

    Max Schmitt (@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 :(

  5. mxschmitt commented on May 30, 2024

    @mxschmitt
    Contributor

    LFMM (@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.

  6. LFMM-33 commented on May 30, 2024

    @LFMM-33
    Author

    Max Schmitt (@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.

  7. mxschmitt commented on May 30, 2024

    @mxschmitt
    Contributor

    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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions