Skip to content

v3.2.0

Compare
Choose a tag to compare
@ClericPy ClericPy released this 18 May 16:29
· 18 commits to master since this release
  • add Tab.info, Tab.get_info, Tab.new_tab, Tab.browserContextId, Tab.get_targets

Tab.new_tab demo

import asyncio

from ichrome import AsyncChromeDaemon


async def main():
    async with AsyncChromeDaemon(headless=False, disable_image=True) as cd:
        async with cd.incognito_tab() as tab:
            url = 'http://www.bing.com/'
            await tab.goto(url, timeout=3)
            MUIDB = (await tab.get_cookies_dict([url])).get('MUIDB')
            new_tab = await tab.new_tab()
            tab_exist = bool(await tab.chrome.get_tab(new_tab.tab_id))
            assert tab_exist
            async with new_tab(auto_close=True) as tab:
                # same context, so same cookie
                MUIDB2 = (await tab.get_cookies_dict([url])).get('MUIDB')
                # print(MUIDB, MUIDB2, MUIDB == MUIDB2)
                assert MUIDB == MUIDB2
            # the new_tab auto closed
            tab_exist = bool(await tab.chrome.get_tab(new_tab.tab_id))
            assert not tab_exist


asyncio.run(main())