This repository has been archived by the owner on May 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
Support browser contexts to launch different sessions #44
Comments
test case, Judging by the returned cookies of 2 requests import asyncio
from pyppeteer import launch
from pyppeteer.launcher import connect
async def main():
browser = await connect({'browserWSEndpoint': "ws://127.0.0.1:9222/devtools/browser/622533f4-7515-49d1-83b4-40f1780f4345"})
page, browserContextId = await browser.newIncognitoPage()
await page.goto('http://www.baidu.com')
cookies = await page.cookies()
print(cookies)
await page.close()
if browser._connection:
await browser._connection.send('Target.disposeBrowserContext', {
'browserContextId': browserContextId
})
await browser.disconnect()
asyncio.get_event_loop().run_until_complete(main()) |
Closed
await page.close() , need to release BrowserContext |
puppeteer/puppeteer#85 Has been fixed in PR puppeteer/puppeteer#2523, i guess incognito pages can be added in a clean way now |
When will it be updated |
Not sure, but for now I'm doing this: (BEWARE: It breaks things like setting timeout or anything else that you try to set, it's hacky and if you put this is code that other people will have to use they will kill you and your family) browser = await launch()
async def newIncognitoPage(self):
"""Make new page on this browser and return its object."""
browserContextId = (await self._connection.send(
'Target.createBrowserContext', {})).get('browserContextId')
targetId = (await self._connection.send(
'Target.createTarget',
{'url': 'about:blank', 'browserContextId': browserContextId})).get('targetId')
target = self._targets.get(targetId)
if target is None:
raise BrowserError('Failed to create target for page.')
if not await target._initializedPromise:
raise BrowserError('Failed to create target for page.')
page = await target.page()
if page is None:
raise BrowserError('Failed to create page.')
return page
browser.newIncognitoPage = types.MethodType(newIncognitoPage, browser)``` |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
puppeteer/puppeteer#85
add to Line 110
https://github.com/miyakogi/pyppeteer/blob/dev/pyppeteer/browser.py#L110
The text was updated successfully, but these errors were encountered: