Coder Social home page Coder Social logo

Comments (8)

github-actions avatar github-actions commented on May 20, 2024

Please fix the format of your markdown:

7 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

from rod.

ysmood avatar ysmood commented on May 20, 2024

用法的问题,create 里处理 auth

from rod.

wAnFen1017 avatar wAnFen1017 commented on May 20, 2024

用法的问题,create 里处理 auth

如果改成在create中处理时则会报 panic: {-32000 Invalid state for continueInterceptedRequest }

create := func() *rod.Browser {
		go browser.MustHandleAuth(user, pwd)()
		return browser.MustIncognito()
	}

from rod.

ysmood avatar ysmood commented on May 20, 2024

如果在外围处理,需要处理每个 auth 事件,browser.MustHandleAuth 只处理碰到的第一个,你看看它的源代码就懂了

from rod.

wAnFen1017 avatar wAnFen1017 commented on May 20, 2024

如果在外围处理,需要处理每个 auth 事件,browser.MustHandleAuth 只处理碰到的第一个,你看看它的源代码就懂了

我在每个goroutine中做处理不可实现吗,或者如果在外围统一处理的话,我查到是使用EachEvent去控制全部活动,我改成这样,依旧报错 panic: {-32000 Invalid state for continueInterceptedRequest }

	go browser.EachEvent(func(e *proto.FetchAuthRequired) {
		fakeAuth := &proto.FetchAuthChallengeResponse{
			Response: proto.FetchAuthChallengeResponseResponseProvideCredentials,
			Username: user,
			Password: pwd,
		}
		err := proto.FetchContinueWithAuth{
			RequestID:             e.RequestID,
			AuthChallengeResponse: fakeAuth,
		}.Call(browser)
		if err!=nil{
			panic(err)
		}
	}, func(e *proto.FetchRequestPaused) {
		err := proto.FetchContinueRequest{
			RequestID: e.RequestID,
		}.Call(browser)
		if err!=nil{
			panic(err)
		}
	})()

	browsePool := rod.NewBrowserPool(20)
	create := func() *rod.Browser {
		return browser.MustIncognito()
	}
        // browser.MustPage()

from rod.

ysmood avatar ysmood commented on May 20, 2024

那你可能需要自己 debug 一下,应该是用法的问题,这方面 chromium cdp 缺少文档说明,只能猜测用法,让我来和让你来是一样的。

你这里报错的意思是 FetchContinueRequest 用法错误

from rod.

wAnFen1017 avatar wAnFen1017 commented on May 20, 2024

我看了您另外的一个回答 #654 ,我感觉我和他的问题应该是差不多的,但是我这里使用了BrowserPool,所以我猜测是不是BrowserPool的问题,以下是我的完整代码,此时报错信息是 navigation failed: net::ERR_INVALID_AUTH_CREDENTIALS

// Package main
// @Time      : 2023-12-06 09:47
// @Author    : wAnFen
// @File      : render.go
// @Go        : 1.21.3

package main

import (
	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/launcher"
	"github.com/go-rod/rod/lib/proto"
	"log"
	"sync"
)

func RunRod(url string) {
	var rodUrl string
	l := launcher.New().
		Headless(false).
		Leakless(true).
		NoSandbox(true).
		Delete("enable-automation").
		Set("ignore-certificate-errors").
		Set("ignore-certificate-errors-spki-list").
		Set("ignore-ssl-errors").
		Set("disable-blink-features", "AutomationControlled").
		Set("disable-setuid-sandbox").
		Set("disable-gpu").
		Set("disable-dev-shm-usage").
		Set("unlimited-storage").
		Set("disable-accelerated-2d-canvas").
		Set("full-memory-crash-report")

	l = l.Proxy("http://127.0.0.1:6501")

	path, has := launcher.LookPath()
	if has == true {
		rodUrl = l.Bin(path).MustLaunch()
	} else {
		rodUrl = l.MustLaunch()
	}

	log.Println("StartURL : ", rodUrl)
	browser := rod.New().ControlURL(rodUrl).MustConnect()

	browser.MustIgnoreCertErrors(true)

	user := "user"
	pwd := "pwd"

	go browser.EachEvent(func(e *proto.FetchAuthRequired) {
		fakeAuth := &proto.FetchAuthChallengeResponse{
			Response: proto.FetchAuthChallengeResponseResponseProvideCredentials,
			Username: user,
			Password: pwd,
		}
		err := proto.FetchContinueWithAuth{
			RequestID:             e.RequestID,
			AuthChallengeResponse: fakeAuth,
		}.Call(browser)
		if err != nil {
			panic(err)
		}
	}, func(e *proto.FetchRequestPaused) {
		err := proto.FetchContinueRequest{
			RequestID: e.RequestID,
		}.Call(browser)
		if err != nil {
			panic(err)
		}
	})()

	browsePool := rod.NewBrowserPool(20)
	create := func() *rod.Browser {
		return browser.MustIncognito()
	}

	var wg sync.WaitGroup
	for i := 0; i <= 3; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			b := browsePool.Get(create)
			page, err := b.Page(proto.TargetCreateTarget{URL: url})
			if err != nil {
				log.Println("browser.Page Err : ", err)
			}
			println(page.MustElement("html").MustText())
		}()
	}
	wg.Wait()
}

func main() {
	RunRod("http://api.ipify.org")
}

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.