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

Some fixes and improvements #19

Closed
wants to merge 11 commits into from
Closed

Some fixes and improvements #19

wants to merge 11 commits into from

Conversation

yoori
Copy link

@yoori yoori commented Nov 17, 2024

I hope, that now we have place to collect fixes for nodriver.
I'm trying to stabilize it for flare-bypasser and am debug now an intermittent issue with CDP replies being lost - case when some call can be timeouted (navigate, screenshot), but internally looks like listening loop don't see answer for CDP command, but recv it when we start browser closing (by timeout = 60) ...

Here few fixes and improvements, that I need, and I think - they are useful for the project:

  • cookie parsing fix (CookieJar.get_all don't work for chrome >=129)
  • websockets 14.0 adaptation
  • don't use __count__ for CDP message id generation (it is strange) and never drop it to zero - I'm putting this part in order to prevent the loss of answers due to repetitions of CDP message id.
  • some little changes

Copy link
Owner

@stephanlensky stephanlensky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I added a few comments which I think need to be addressed before we can merge this.

I also have a general question - what was the breaking change in websockets 14.0 and how does this PR address it? I didn't look into that at all yet, so I'm not sure what to look for here.

BTW, would you mind listing your changes in CHANGELOG.md under the [Unreleased] section? Feel free to add your username at the end of each bullet point if you'd like credit.

Comment on lines +368 to +372
try :
_, stderr_bytes = await self._process.communicate()
stderr = stderr_bytes.decode()[:1000]
except Exception :
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the try/except needed? when would this cause an exception?

if this is to handle self._process being None, we should check for that explicitly instead of doing try/except

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, why are we truncating to first 1000 characters? maybe if anything getting the last 1000 characters would be more useful?

Copy link
Author

@yoori yoori Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about exception handling : communicate is hard method (it use system calls and can raise exception by much reasons), and raise exception in block that already process exception isn't good for me ... in this case we can live with original exception without output (and debug output separatly)
about output : I got first 1000 chars, because I don't expect here much output (we only started chrome here and don't pushed some commands) - it is trivial protection for memory overuse for strange cases (for example : when chrome executable file replaced with something)

Comment on lines +381 to +382
""" +
("Browser error output:" + stderr if stderr else '')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I've been meaning to add something like this. very useful

Comment on lines +1494 to +1496
if isinstance(json, str):
# Some chrome versions return partitionKey as string
return cls(json, False)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity are there any docs on this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find something in docs, simple logged CDP message and got from practice usage of chrome >=129

return self.websocket.closed
return (not self.websocket)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you added

websocket = None

below, so this will work when we close the connection, but aren't there also other ways for the websocket to get closed? what if the browser closes the connection?

to handle all cases, we should probably do like

self.websocket is None or self.websocket.closed

(this applies to the other places you changed this as well)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closed property removed in 14 and logic of websockets authors :
closed can be changed only on operations (send/recv) - here no any loop in websockets that check sockets in background
closed attribute can be filled only on operations, that already raise ConnectionClosedError
using of closed attribute after this exception is bad design for applications

zendriver/core/browser.py Outdated Show resolved Hide resolved
requires-python = ">=3.10"
requires-python = ">=3.9"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, this change needs to be reverted if you want this PR to get merged - I am sticking with >=3.10 for the X | Y union syntax for type annotations.

BTW, sorry for the delay in responding, I need to do some further research to understand the websockets==14.0 changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I replace|with typing.Union ? I need 3.9 compatibility …

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I recreated MR, (can't find way to change branch in already created MR), I can't rollback python 3.9 adaptation in main and created MR with other branch : #22

@yoori
Copy link
Author

yoori commented Nov 21, 2024

Pull request recreated (for merge from other source branch) : #22
sorry, that we lose conversions ...

@yoori yoori closed this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants