Skip to content

Is it possible to execute script immediately after the page is navigated to? #179

Answered by thalissonvs
Vincent-Lin-UF asked this question in Q&A
Discussion options

You must be logged in to vote

There's also another way, using events:

import asyncio
from functools import partial
from pydoll.browser import Chrome
from pydoll.protocol.page.events import PageEvent


async def main():
    browser = Chrome()
    tab = await browser.start()
    await tab.enable_page_events()

    async def on_page_event(event, tab):
        # your script here
        await tab.execute_script("return document.title")  # noqa: F821

    await tab.on(PageEvent.LOAD_EVENT_FIRED, partial(on_page_event, tab))
    await tab.go_to('https://google.com/') # this will trigger the event and 
    # run the script immediately after the page is loaded

asyncio.run(main())

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thalissonvs
Comment options

Answer selected by Vincent-Lin-UF
@Vincent-Lin-UF
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants