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

【SetDocumentContent】能像puppeteer一样监听load #901

Closed
tyouzu1 opened this issue Jul 11, 2023 · 4 comments
Closed

【SetDocumentContent】能像puppeteer一样监听load #901

tyouzu1 opened this issue Jul 11, 2023 · 4 comments
Labels
question Questions related to rod

Comments

@tyouzu1
Copy link

tyouzu1 commented Jul 11, 2023

背景: 我是Nodejs服务迁移到go这边,选了rod,然后因为之前主要逻辑的实现是通过puppeteer的setContent来实现的。html内容内可能有各种url资源加载。所以需要等待一段时间。

 await page.setContent(data.html, { waitUntil: 'load' });

问题:转到rod这边后,找到了SetDocumentContent,但是SetDocumentContent没有这种参数,于是就使用了各种等待的方法。
然后发现除了MustWaitLoad,其他的基本都是超时时间,这样等待的话效率上太低,

现状:
SetDocumentContent后MustWaitLoad不能等待资源加载,其他等待方法均为超时等待,MustWaitLoad为监听load。只能说通过拦截请求来实现我要的效果,但怎么都感觉不是最佳实践。

		utils.E(proto.FetchEnable{
			Patterns: []*proto.FetchRequestPattern{
				{URLPattern: "*"},
			},
		}.Call(page))
		go page.EachEvent(func(e *proto.FetchRequestPaused) {
			if e.Request.URL == "http://example.com/" {
				utils.E(proto.FetchFulfillRequest{
					RequestID:    e.RequestID,
					ResponseCode: 200,
					Body:         html,
				}.Call(page))
			} else {
				utils.E(proto.FetchContinueRequest{RequestID: e.RequestID}.Call(page))
			}
		})()

		page.MustNavigate("http://example.com/")
		page.MustWaitLoad()

需求:SetDocumentContent能像puppeteer一样去监听load,或者说又什么其他办法可以实现?

@tyouzu1 tyouzu1 added the enhance New feature or request label Jul 11, 2023
@tyouzu1
Copy link
Author

tyouzu1 commented Jul 11, 2023

@ysmood

@github-actions
Copy link

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

Please fix the format of your markdown:

2 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```js"]
4 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

generated by check-issue

@ysmood
Copy link
Member

ysmood commented Jul 11, 2023

page.MustWaitStable()

@ysmood ysmood added question Questions related to rod and removed enhance New feature or request labels Jul 11, 2023
@tyouzu1
Copy link
Author

tyouzu1 commented Jul 11, 2023

page.MustWaitStable()

感谢…本地版本有点低 难怪没找到😭

@tyouzu1 tyouzu1 closed this as completed Jul 11, 2023
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

2 participants