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

Feature Request: Connect Options - Allow Authorization Header #7218

Closed
dylanlive opened this issue May 7, 2021 · 6 comments · Fixed by #9314 or #9322
Closed

Feature Request: Connect Options - Allow Authorization Header #7218

dylanlive opened this issue May 7, 2021 · 6 comments · Fixed by #9314 or #9322

Comments

@dylanlive
Copy link

dylanlive commented May 7, 2021

Feature Request

I'd like to connect to a browserWSEndpoint that is protected by authentication. It would be nice to be able to provide an Authorization Bearer <token> on the connection, and every request thereafter to that endpoint.

I'm specifically wanting the Authorization Header, but this probably could just be generic to allowing any headers on all requests.

I vision within the connect options, provide a headers option
https://github.com/puppeteer/puppeteer/blob/v9.1.1/docs/api.md#puppeteerconnectoptions

Example:

browser = await puppeteer.connect({
      browserWSEndpoint: "ws://my.server",
      headers: {
        Authorization: "Bearer hunter2"
      },
});

I'd imagine the change would happen here:

const ws = new WebSocket(url);

To be something similar to:
websockets/ws#473 (comment)

I did see page.setExtraHTTPHeaders(headers), but I don't think this what I'm looking for as it shouldn't just be for a specific page, but for all websocket requests to the server.
https://github.com/puppeteer/puppeteer/blob/v9.1.1/docs/api.md#pagesetextrahttpheadersheaders

@jayflo
Copy link

jayflo commented May 25, 2021

Been looking into this myself. It seems like it may only be relevant when used from Node.js.

In the browser, this uses the javascript websocket (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket)

const ws = new WebSocket(url);

which doesn't allow you to set headers.

Within Node.js it uses the https://github.com/websockets/ws package

const ws = new NodeWebSocket(url, [], {

which should allow you to set headers (https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketaddress-protocols-options) via Node.js's http(s).request options.

@stale
Copy link

stale bot commented Jun 24, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jun 24, 2022
@dylanlive
Copy link
Author

Please leave open :)

@stale stale bot removed the unconfirmed label Jun 24, 2022
@stale
Copy link

stale bot commented Aug 30, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Aug 30, 2022
@dylanlive
Copy link
Author

still valid

@dylanlive
Copy link
Author

@jayflo Good catch! Finally got around to experimenting with some local changes using patch-package and I can confirm the correct area to add the headers to is

headers: {
'User-Agent': `Puppeteer ${packageVersion}`,
},

Would be great to be able to optionally configure additional headers from puppeteer.connect() to that function

OrKoN pushed a commit that referenced this issue Nov 24, 2022
… environment (#9314)

**What kind of change does this PR introduce?**

I have browsers pool in some cloud. I want that only users with access
will be able to connect to them. So they must provide token through
headers. But puppeteer does not allow to send headers when connected to
browser by ws connection. So I added this feature.

Closes #7218
OrKoN pushed a commit that referenced this issue Dec 7, 2022
🤖 I have created a release *beep* *boop*
---


<details><summary>puppeteer: 19.4.0</summary>

##
[19.4.0](puppeteer-v19.3.0...puppeteer-v19.4.0)
(2022-12-07)


### Features

* **chromium:** roll to Chromium 109.0.5412.0 (r1069273)
([#9364](#9364))
([1875da6](1875da6)),
closes [#9233](#9233)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * puppeteer-core bumped from 19.3.0 to 19.4.0
</details>

<details><summary>puppeteer-core: 19.4.0</summary>

##
[19.4.0](puppeteer-core-v19.3.0...puppeteer-core-v19.4.0)
(2022-12-07)


### Features

* ability to send headers via ws connection to browser in node.js
environment
([#9314](#9314))
([937fffa](937fffa)),
closes [#7218](#7218)
* **chromium:** roll to Chromium 109.0.5412.0 (r1069273)
([#9364](#9364))
([1875da6](1875da6)),
closes [#9233](#9233)
* **puppeteer-core:** keydown supports commands
([#9357](#9357))
([b7ebc5d](b7ebc5d))


### Bug Fixes

* **puppeteer-core:** avoid type instantiation errors
([#9370](#9370))
([17f31a9](17f31a9)),
closes [#9369](#9369)
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants