diff --git a/docs/api/puppeteer.page.setbypasscsp.md b/docs/api/puppeteer.page.setbypasscsp.md index 036ffb2f12c..ce5daa8d6e7 100644 --- a/docs/api/puppeteer.page.setbypasscsp.md +++ b/docs/api/puppeteer.page.setbypasscsp.md @@ -10,7 +10,7 @@ Toggles bypassing page's Content-Security-Policy. ```typescript class Page { - setBypassCSP(enabled: boolean): Promise; + abstract setBypassCSP(enabled: boolean): Promise; } ``` diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index 81d5da97e25..d8a79cc6dc3 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -1904,10 +1904,7 @@ export abstract class Page extends EventEmitter { * evaluation. Usually, this means that `page.setBypassCSP` should be called * before navigating to the domain. */ - async setBypassCSP(enabled: boolean): Promise; - async setBypassCSP(): Promise { - throw new Error('Not implemented'); - } + abstract setBypassCSP(enabled: boolean): Promise; /** * @param type - Changes the CSS media type of the page. The only allowed diff --git a/packages/puppeteer-core/src/bidi/Page.ts b/packages/puppeteer-core/src/bidi/Page.ts index cadcd009f7b..a149bfad9f1 100644 --- a/packages/puppeteer-core/src/bidi/Page.ts +++ b/packages/puppeteer-core/src/bidi/Page.ts @@ -155,17 +155,6 @@ export class BidiPage extends Page { return this.mainFrame().context().cdpSession; } - override async setUserAgent( - userAgent: string, - userAgentMetadata?: Protocol.Emulation.UserAgentMetadata | undefined - ): Promise { - // TODO: handle CDP-specific cases such as mprach. - await this._client().send('Network.setUserAgentOverride', { - userAgent: userAgent, - userAgentMetadata: userAgentMetadata, - }); - } - constructor( browsingContext: BrowsingContext, browserContext: BidiBrowserContext @@ -214,6 +203,22 @@ export class BidiPage extends Page { this.#keyboard = new BidiKeyboard(this.mainFrame().context()); } + override async setUserAgent( + userAgent: string, + userAgentMetadata?: Protocol.Emulation.UserAgentMetadata | undefined + ): Promise { + // TODO: handle CDP-specific cases such as mprach. + await this._client().send('Network.setUserAgentOverride', { + userAgent: userAgent, + userAgentMetadata: userAgentMetadata, + }); + } + + override async setBypassCSP(enabled: boolean): Promise { + // TODO: handle CDP-specific cases such as mprach. + await this._client().send('Page.setBypassCSP', {enabled}); + } + _setBrowserContext(browserContext: BidiBrowserContext): void { this.#browserContext = browserContext; } diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 0fc2969be45..8f91c415216 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -3455,24 +3455,48 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass after cross-process navigation", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP header", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP header", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP in iframes as well", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP in iframes as well", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP meta tag", "platforms": ["darwin", "linux", "win32"], "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, + { + "testIdPattern": "[page.spec] Page Page.setBypassCSP should bypass CSP meta tag", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[page.spec] Page Page.setCacheEnabled should enable or disable the cache based on the state passed", "platforms": ["darwin", "linux", "win32"],