Skip to content

Commit

Permalink
feat: ability to send headers when connect to browser using puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Dec 9, 2022
1 parent 8496df6 commit c227141
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/webdriverio/src/commands/browser/getPuppeteer.ts
Expand Up @@ -52,6 +52,7 @@ export default async function getPuppeteer (this: WebdriverIO.Browser) {
return this.puppeteer
}

const { headers } = this.options
const caps = (this.capabilities as Capabilities.W3CCapabilities).alwaysMatch || this.capabilities as Capabilities.DesiredCapabilities
/**
* attach to a Selenium 4 CDP Session if it's returned in the capabilities
Expand All @@ -60,7 +61,8 @@ export default async function getPuppeteer (this: WebdriverIO.Browser) {
if (cdpEndpoint) {
this.puppeteer = await puppeteer.connect({
browserWSEndpoint: cdpEndpoint,
defaultViewport: null
defaultViewport: null,
headers
}) as any as PuppeteerBrowser
return this.puppeteer
}
Expand All @@ -73,7 +75,8 @@ export default async function getPuppeteer (this: WebdriverIO.Browser) {
const { hostname, port } = this.options
this.puppeteer = await puppeteer.connect({
browserWSEndpoint: `ws://${hostname}:${port}/devtools/${this.sessionId}`,
defaultViewport: null
defaultViewport: null,
headers
}) as any as PuppeteerBrowser
return this.puppeteer
}
Expand Down
Expand Up @@ -6,6 +6,9 @@ exports[`attach Puppeteer > should pass for Aerokube Moon CDP 1`] = `
{
"browserWSEndpoint": "ws://my.grid:4444/devtools/foobar-123",
"defaultViewport": null,
"headers": {
"Authorization": "OAuth token",
},
},
],
]
Expand All @@ -17,6 +20,9 @@ exports[`attach Puppeteer > should pass for Aerokube Selenoid CDP 1`] = `
{
"browserWSEndpoint": "ws://my.grid:4444/devtools/foobar-123",
"defaultViewport": null,
"headers": {
"Authorization": "OAuth token",
},
},
],
]
Expand Down Expand Up @@ -83,6 +89,9 @@ exports[`attach Puppeteer > should pass for Selenium CDP 1`] = `
{
"browserWSEndpoint": "http://my.grid:1234/session/mytestsession/se/cdp",
"defaultViewport": null,
"headers": {
"Authorization": "OAuth token",
},
},
],
]
Expand Down
13 changes: 11 additions & 2 deletions packages/webdriverio/tests/commands/browser/getPuppeteer.test.ts
Expand Up @@ -23,6 +23,9 @@ describe('attach Puppeteer', () => {
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'foobar'
},
headers: {
Authorization: 'OAuth token'
}
})
})
Expand Down Expand Up @@ -198,7 +201,10 @@ describe('attach Puppeteer', () => {
options: {
hostname: 'my.grid',
port: 4444,
path: '/wd/hub'
path: '/wd/hub',
headers: {
Authorization: 'OAuth token'
}
} as any
})
expect(typeof pptr).toBe('object')
Expand All @@ -221,7 +227,10 @@ describe('attach Puppeteer', () => {
options: {
hostname: 'my.grid',
port: 4444,
path: '/wd/hub'
path: '/wd/hub',
headers: {
Authorization: 'OAuth token'
}
} as any
})
expect(typeof pptr).toBe('object')
Expand Down
2 changes: 1 addition & 1 deletion website/docs/Configuration.md
Expand Up @@ -135,7 +135,7 @@ Default:

### headers

Specify custom `headers` to pass into every WebDriver request.
Specify custom `headers` to pass into every WebDriver request and when connect to browser through Puppeteer using CDP protocol.

:::caution

Expand Down

0 comments on commit c227141

Please sign in to comment.