phantombuster / nickjs

Web scraping library made by the Phantombuster team. Modern, simple & works on all websites. (Deprecated)
https://nickjs.org
ISC License
501 stars 48 forks source link

Unable to Add Header on await tab.open(). #25

Closed mrhodd closed 6 years ago

mrhodd commented 6 years ago

I'm using NickJs browser emulation and am attempting to add a header when opening a page. I'm monitoring the request in Fiddler and see that the header is not being added.

How do I add the header?

Here's my current code:

await tab.open("https://www.google.com/", {headers: {"Accept-Language": "en-US,en;q=0.9"}})

paps commented 6 years ago

The header feature is not yet implemented for the Chrome backend unfortunately.

I will try to implement it soon. In the meantime, as an alternative, you can use

    await tab.driver.client.Network.setExtraHTTPHeaders({
        headers: {
            "Header key": "Header value",
        }
    })

Do this before your open() call.

This makes use of the underlying CDP (chrome-remote-interface) client which implements the Chrome DevTools Protocol (see doc for the Network namespace)

mrhodd commented 6 years ago

Awesome!! Thank you for the response!

This has resolved my issue!

mrhodd commented 6 years ago

Side note, is it possible to set the order of this header? I noticed it doesn't appear in the same order as a request from my browser does (and unfortunately I do think that header order matters here...).

paps commented 6 years ago

I'm not aware of any way to control the order of headers, sorry