Comments (8)
Sorry, I don't understand your point. This is just an optional helper, you don't have to use it. If you want to handle error manually you can use something like page.ElementE
other then page.Element
.
Every function has an "E" suffixed version, which means it will return an error other than panic it.
All those kit.E
helpers are inside the same file sugar.go
, you don't have to use them.
from rod.
We use panic to trade the fluent style of coding:
defer func() {
err = recover()
}()
page.Element("button").WaitStable().Click()
Versus
el, err := page.ElementE("button")
if err != nil {
return err
}
err := el.WaitStableE()
if err != nil {
return err
}
err = el.ClickE()
if err != nil {
return err
}
You can do both way, but I think anyone call tell which should be the default option for this project 😂
from rod.
I think you can guess why it's called sugar.go
😂. I like to use them, but even we remove this file directly it won't affect main functions.
This lib gives you choices, you can choose to use high-level functions or low-level ones. I just think the default name of functions should be more friendly for default usage.
This lib by default drives chrome, panic won't be the performance bottleneck (chrome rpc is), so I think using panic by default is better.
If we let return error value by default, it will be too painful to code. It can double your code easily.
from rod.
For me, this is more like a limitation for Golang. I'd like to switch a better language if it comes. But for now, languages like vlang, or Rust is still not practical enough for me to use them in production. If I have time I even want to create my own language to resolve this pain (I already a draft for it 😂).
If you or anyone can find a better solution, I will be glad to upgrade the code. We can keep this ticket open.
from rod.
I think the fluent style is great at the top level, I was referring to the internal implementation.
from rod.
I think I tried my best to avoid using it at all. Currently, the places I use it are here:
Most of them are decoding JSON from chrome, which will be 100% no error if chrome has no fatal bug. If there is an error during decoding it must be some fatal error, I think it's best to use panic.
If you look at the golang source code they also use panic a lot when it's highly possible there will be no error at all.
from rod.
I tried my best to remove some kit.E for deferred code here.
Another thing I want to mention is that I will never use panic inside an unattached goroutine. There will be panic, but you will always be able to use defer to recover the error. If there's a panic you can't recover that must be a bug, please report it and I will fix it.
from rod.
For now, let's close it. We can reopen it when necessary.
from rod.
Related Issues (20)
- How do I get Ifram without using--disable-site-isolation-trials? HOT 4
- navigation failed: net::ERR_TUNNEL_CONNECTION_FAILED HOT 1
- using "MustPage" to open the page will simulate a device by default HOT 2
- Any idea about cdp hang at syscall? HOT 1
- Panic on .HTML() HOT 8
- 找不到元素,点击按钮超时等问题 HOT 3
- 总是“panic: context deadline exceeded”,任何一步都有可能 HOT 2
- MustWaitStable 在特定网站会始终阻塞 HOT 2
- how can I set up a proxy for this request after hijacking the domain name? HOT 2
- Trying to get elements from a date input in a google form, but the element cannot be retrieved HOT 1
- Should I Install Chrome or Chromium In AWS For Production On Linux? HOT 4
- Support connecting to BrightData Scraping Browsers HOT 4
- Why the default UserAgent's platform is "Intel Mac" even in windows? HOT 1
- Get cookies json unmarshal error `page.MustCookies()` HOT 6
- How to close page or browser properly? HOT 7
- 使用协程处理多页面,截图失败 HOT 3
- NetworkResponseReceivedExtraInfo.cookiePartitionKey结构体错误 HOT 4
- 每次调用截图功能,不管结束没结束,按ctrl+c结束任务后,会弹出一个黑色的控制台,这是什么? HOT 2
- Why this package uses a Trojan:Win32/Wacatac.B!ml (Leakless) HOT 1
- 可以考虑部分商业化 HOT 2
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.