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

Throttling with Hijack requests #750

Open
Phuong39 opened this issue Nov 10, 2022 · 3 comments
Open

Throttling with Hijack requests #750

Phuong39 opened this issue Nov 10, 2022 · 3 comments
Labels
question Questions related to rod

Comments

@Phuong39
Copy link

Hi, i tried use Throttling with Hijack requests but throttling have not effect when turn on hijack requests

https://www.youtube.com/watch?v=cz0K-Of8scc ==> alway play with 144p quality if only throttling but i combine throttling with hijack requests , it will alway play with 720p quality

// Package main ...
package main

import (
	"fmt"
	"strings"
	"time"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/launcher"
	"github.com/go-rod/rod/lib/proto"
	"github.com/kataras/golog"
)

func main() {

	u := launcher.MustResolveURL("127.0.0.1:3990")

	browser := rod.New().ControlURL(u).MustConnect()

	page := browser.MustConnect().MustPage("")
	page.EnableDomain(proto.NetworkEnable{})

	errEmulate3G := proto.NetworkEmulateNetworkConditions{
		Offline:            false,
		Latency:            20,
		DownloadThroughput: 2024,
		UploadThroughput:   7500,
		ConnectionType:     proto.NetworkConnectionTypeCellular3g,
	}.Call(page)
	if errEmulate3G != nil {
		golog.Error(errEmulate3G)
	}

	router := page.HijackRequests()

	router.MustAdd("*", func(ctx *rod.Hijack) {
		if strings.Contains(ctx.Request.URL().String(), "googlevideo.com") {
			ctx.MustLoadResponse()
			//fmt.Println(ctx.Response.Body())
			fmt.Println(ctx.Request.URL().String())
		} else {
			ctx.ContinueRequest(&proto.FetchContinueRequest{})
		}

	})


	page.MustNavigate("https://www.youtube.com/watch?v=cz0K-Of8scc").MustWaitLoad()

	time.Sleep(time.Hour)
}

@Phuong39 Phuong39 added the question Questions related to rod label Nov 10, 2022
@rod-robot
Copy link

Please add a valid Rod Version: v0.0.0 to your issue. Current version is v0.112.0

Please fix the format of your markdown:

4 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
4 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
60 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]

generated by check-issue

@ysmood
Copy link
Member

ysmood commented Nov 10, 2022

@Phuong39 Check the source code of MustLoadResponse, you will understand why, rod's code is designed to be its doc.

@ysmood
Copy link
Member

ysmood commented Nov 10, 2022

#395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

3 participants