GithubHelp home page GithubHelp logo

Comments (11)

ysmood avatar ysmood commented on July 18, 2024

You can set the request auth header by this API: https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setExtraHTTPHeaders

The header looks like this Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==.

dXNlcjpwYXNzd29yZA== is base64 of user:password

from rod.

zjlx avatar zjlx commented on July 18, 2024

I try it :
page.Call("Network.setExtraHTTPHeaders", cdp.Object{ "Proxy-Authorization": "Basic dXNlcjpwYXNzd29yZA==", })
the error is panic: {"code":-32602,"message":"Invalid parameters","data":"headers: object expected"}
Is the parameter format incorrect?

from rod.

ysmood avatar ysmood commented on July 18, 2024

The error message is already telling you you missed the headers πŸ˜‚

It's like Call({ headers: { a: b } }), not Call({ a: b })

from rod.

ysmood avatar ysmood commented on July 18, 2024

BTW, I added page.SetExtraHeaders in version v0.29.1, you can use that directly:

This is the example code:

https://github.com/ysmood/rod/blob/f397ccbb88efc50352fc97574d71b0d3655a8755/page_test.go#L57

from rod.

ysmood avatar ysmood commented on July 18, 2024

The new version of Rod is type-safe when you send low-level requests to chrome. This kind of issue won't happen again, check the example:

https://github.com/ysmood/rod/blob/3ff68f7d645f24c0978878939164f01bd39d88a2/examples_test.go#L175

from rod.

zjlx avatar zjlx commented on July 18, 2024

I use page.SetExtraHeaders("Proxy-Authorization", "Basic "+temp) but it not work , is it rigth?
key/value use comma separated?
Can you change it to
var dict map[string]string = map[string]string{"Proxy-Authorization":"Basic "+temp} page.SetExtraHeaders(dict)
And v0.29.1 can't use Call and Cdp.Object anymore?

from rod.

ysmood avatar ysmood commented on July 18, 2024

Check my previous comment, it's type-safe now, that's the new way to use the low-level API, cdp.Object is not type-safe.

If you really want to use raw json, you can do something like:

	// Or even more lower way to use raw json to send request to chrome.
	ctx, client, sessionID := page.CallContext()
	client.Call(ctx, sessionID, "Network.SetCookie", map[string]string{
		"name":  "rod",
		"value": "test",
		"url":   "https://github.com",
	})

vs

	proto.NetworkSetCookie{
		Name:  "rod",
		Value: "test",
		URL:   "https://github.com",
	}.Call(page)

These two ways are the same.

from rod.

ysmood avatar ysmood commented on July 18, 2024

with map[string]string you have to write more code.

SetHeaders(map[string]string{"a": "b"})

vs

SetHeaders("a", "b")

The later is obviously shorter. When you have multiple pairs, you can do:

SetHeaders(
  "key1", "value1",
  "key2", "value2",
)

from rod.

ysmood avatar ysmood commented on July 18, 2024

Thanks for your report. The v0.30.1 added the HandleAuth helper to deal with your problem.

I tested with mitmproxy --showhost --proxyauth a:b, it works well.

Here's the example to use it:

https://github.com/ysmood/rod/blob/3ae35ce463f28e3ce8055e6dafda5eb33f39fc53/browser_test.go#L70

from rod.

ysmood avatar ysmood commented on July 18, 2024

@zjlx about the breaking change issue, check this answer: How versioning is handled

from rod.

zjlx avatar zjlx commented on July 18, 2024

Thanks for your report. The v0.30.1 added the HandleAuth helper to deal with your problem.

I tested with mitmproxy --showhost --proxyauth a:b, it works well.

Here's the example to use it:

https://github.com/ysmood/rod/blob/3ae35ce463f28e3ce8055e6dafda5eb33f39fc53/browser_test.go#L70

Thank you so much for the changes. It is working well.

from rod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.