in src/nova_act/impl/playwright.py [0:0]
def _init_browser_context(self, context: BrowserContext, trusted_page: Page) -> Page:
# The protocol here is as follows:
#
# - Navigate a trusted page. Trusted here means it won't tamper with the content script.
# - Wait for the page to register listeners.
# - Send the encryption key through that page to the extension service worker.
# - Service worker will then register the tab id with the SDK.
# - Open the starting page and close the trusted page.
context.expose_function(HANDLE_ENCRYPTED_MESSAGE_FUNCTION_NAME, self._window_message_handler.handle_message)
# Send in the secret key through a trusted page.
trusted_page.goto("https://nova.amazon.com/agent-loading")
self._initialize_page(trusted_page)
trusted_page.wait_for_selector("#autonomy-listeners-registered", state="attached")
trusted_page.evaluate(POST_MESSAGE_EXPRESSION, self._encrypter.make_set_key_message())
# The default opened page may contain infobars with messages while new pages should not.
first_page = context.new_page()
first_video_path = None
if self._record_video: # We will delete this video since we're closing this page
first_video_path = cast(Video, trusted_page.video).path()
trusted_page.close()
# Navigate to the starting page, from the default (about:blank).
self._initialize_page(first_page)
first_page.goto(self._starting_page, wait_until="domcontentloaded")
first_page.wait_for_selector("#autonomy-listeners-registered", state="attached")
if first_video_path and os.path.exists(first_video_path):
os.remove(first_video_path)
context.on("page", PlaywrightInstanceManager._initialize_page)
return first_page