Rayrun
← Back to Discord Forum

Service Worker not available

Hello,

I'm facing an issue while testing service workers in Playwright using Pytest within a Docker container. When evaluating navigator.serviceWorker, I get the value None. Has anyone encountered a similar problem and found a solution?

Test python code:

def test_homepage(browser: Browser):
    context = browser.new_context(service_workers='allow')
    page = context.new_page()

    # pass
    assert page.evaluate('navigator') is not None
    
    # fail
    assert page.evaluate('navigator.serviceWorker') is not None

    page.goto(HOMEPAGE)
    expect(page).to_have_title(re.compile("Web App"))

The previous test code gives the following output:

>       assert page.evaluate('navigator.serviceWorker') is not None
E       AssertionError: assert None is not None
E        +  where None = <bound method Page.evaluate of <Page url='about:blank'>>('navigator.serviceWorker')
E        +    where <bound method Page.evaluate of <Page url='about:blank'>> = <Page url='about:blank'>.evaluate

Thanks!

This thread is trying to answer question "Why is `navigator.serviceWorker` returning `None` when testing service workers in Playwright using Pytest within a Docker container and how can this be resolved?"

0 replies

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].