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
…#9354)

* chore: bump puppeteer-core from 19.3.0 to 19.4.0

* feat: ability to send headers when connect to browser using puppeteer
  • Loading branch information
DudaGod committed Dec 9, 2022
1 parent 2b5dad9 commit d2a7854
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/devtools/package.json
Expand Up @@ -43,7 +43,7 @@
"chrome-launcher": "^0.15.0",
"edge-paths": "^2.1.0",
"import-meta-resolve": "^2.1.0",
"puppeteer-core": "19.3.0",
"puppeteer-core": "19.4.0",
"query-selector-shadow-dom": "^1.0.0",
"ua-parser-js": "^1.0.1",
"uuid": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/wdio-devtools-service/package.json
Expand Up @@ -44,7 +44,7 @@
"istanbul-lib-report": "^3.0.0",
"istanbul-reports": "^3.1.4",
"lighthouse": "8.6.0",
"puppeteer-core": "19.3.0",
"puppeteer-core": "19.4.0",
"speedline": "^1.4.3",
"stable": "^0.1.8",
"webdriverio": "8.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/webdriverio/package.json
Expand Up @@ -85,7 +85,7 @@
"lodash.clonedeep": "^4.5.0",
"lodash.zip": "^4.2.0",
"minimatch": "^5.0.0",
"puppeteer-core": "19.3.0",
"puppeteer-core": "19.4.0",
"query-selector-shadow-dom": "^1.0.0",
"resq": "^1.9.1",
"rgb2hex": "0.2.5",
Expand Down
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 d2a7854

Please sign in to comment.