Comments (3)
The final design I think will be like:
func main () {
router := browser.HijackRequests("a.com", "b.com")
defer router.Stop()
router.Host("a.com").
GET("/user/:id", func(ctx rod.ProxyContext) {
if ctx.Param("id") != "abc" {
ctx.Next()
return
}
ctx.JSON(mock_user_data)
}).
DELETE("/user/:id", func(ctx rod.ProxyContext) {
ctx.Write(200, "OK")
})
router.POST("/upload", func(ctx rod.ProxyContext) {
fmt.Println(ctx.Form())
ctx.Next()
})
go router.Run()
}
I will try to use https://github.com/gin-gonic/gin directly if it's not too much work.
from rod.
browser.Hijack(`https://*/*`, func(ctx Context) (pass_to_browser bool) {
// deal with specific page
if Equal(ctx.Page, browser.Pages()[0]) {
switch ctx.Request.Host {
case "api.example.com":
{
switch ctx.Request.Path {
case "/status":
{
// mock
ctx.JSON(200, rod.H{
"message": "ok",
})
return false
}
case "/check":
{
// modify a header and pass to browser to continue the request
ctx.Request.Header.Set("Token", "my token")
return true
}
}
}
case "npmjs.com":
{
// modify the host and pass to browser to continue the request
ctx.Request.Host = "cdn.jsdelivr.net"
return true
}
}
}
return true
})
I don't know if this is possible with CDP but I think hijack api like this will be very useful and, powerful.
from rod.
Usually, we don't design like pass_to_browser
, we use middleware like interface:
go browser.Hijack("/user/:id", func(ctx rod.ProxyContext) (stop bool) {
ctx.Next()
return false
})
from rod.
Related Issues (20)
- Add support for Linux Arm? for downloading etc. HOT 4
- Add an initEvents public function with a Browser structure HOT 5
- page.Navigate(url), the page is like blocked HOT 1
- 测试时如何获取当前网页 HOT 5
- Click Button Eval Js Not Working HOT 4
- 获取点击后的response失败 HOT 2
- How to hide chromium command prompt HOT 2
- Element存在,但Element.MustHas却为false,检测不到Element HOT 2
- How to open a new Chrome window while using remote control HOT 4
- Using go-rod with firefox, failing to start new instance of firefox HOT 6
- How to disable the dialog when open External protocols HOT 2
- How to Set or replace response headers HOT 2
- Proxy and Hijack HOT 3
- Just a recipe to run a go-rod program as systemd service HOT 1
- How to Log CDP Logs to a File or Use slog HOT 2
- Failed to deserialize params.body - BINDINGS: binary value expected at position 61 HOT 5
- failed page screenshot in defer HOT 2
- launcher docker 是否支持常驻且直接连接 HOT 4
- Examples fail on Ubuntu 24.04 with "No usable sandbox!" HOT 8
- Open the webpage, the page size is changed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rod.