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

Bugfix of multiple instance creation of a single page #239

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

bytefoot
Copy link

Refrence Issue:

#238 Browser.pages() is being inconsistent when new page is created.

Fix

Multiple creation instance of a single page has been fixed. The instance variable '_page' is instantly updated ensuring only one object is created for a page in the respective target of the browser. Type of '_page' has been changed to an Awaitable.

Comment on lines +76 to +77
self._page = new_page = asyncio.create_task(self._create_page())
return await new_page
Copy link
Member

Choose a reason for hiding this comment

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

Sorry the intent of this doesn't seem entirely clear to me, is there any difference in the following code?

                return await self._create_page()

Copy link
Author

Choose a reason for hiding this comment

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

On usage i happen to find that this particular function gets called twice almost at the same time. This leads to creation of 2 Page objects for the same tab/page. One of the Page objects gets added to the pages list, and one is just dropped off. By storing the page creation function as an Task object in the instance variable self._page., the first call works as before. Now, the second time function is called, the function doesnt create another Page object but instead awaits from the instance variable self._page, and hence both the calls would return the same Page object. (please check line 83, 84).

I just notice that just viewing the highlighted changes, my line seems unnecessary; I think you would understand better if you looked at the complete function in the file.

Copy link
Member

Choose a reason for hiding this comment

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

I realize taken in isolation, yeah it looks unecessary, but I did read through the whole changeset. I'll take a look at the relevant bug and try to reproduce here so that I know exactly what's going on. Thanks for sending in this PR BTW!

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.

None yet

2 participants