Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response from service worker not considered a load event #30405

Open
eiriksm opened this issue Oct 14, 2024 · 0 comments
Open

Response from service worker not considered a load event #30405

eiriksm opened this issue Oct 14, 2024 · 0 comments

Comments

@eiriksm
Copy link

eiriksm commented Oct 14, 2024

Current behavior

I am trying to test a much more convoluted setup than this, but I boiled it down to a very simple reproducible repo that can be found here:

https://github.com/eiriksm/cy-repro

Basically. What I am struggling with, seems to be that when a document is loaded like so:

            event.respondWith(
                (async () => {
                  return new Response(`<html><body class="sw-body"><h1>200</h1>${url} found<script>window.onload = function() { let p = document.createElement('p');p.innerHTML = 'this is written with document write on load';document.querySelector('body').append(p) }</script></body></html>`, {
                    status: 200,
                    headers: {"Content-Type": "text/html"},
                  })
                })(),
              )

It seems cypress thinks the document is still loading and ends up timing out:

     CypressError: Timed out after waiting `10000ms` for your remote page to load.

Your page did not fire its `load` event within `10000ms`.

You can try increasing the `pageLoadTimeout` value in `cypress.config.js` to wait longer.

Browsers will not fire the `load` event until all stylesheets and scripts are done downloading.

When this `load` event occurs, Cypress will continue running commands.

As you can see, I am actually making sure the browser knows the onload event is fired, by writing that in the body when it happens.

Screenshot from 2024-10-14 08-48-00

Desired behavior

Recognise that the document is loaded, and not trigger the timeout error

Test code to reproduce

https://github.com/eiriksm/cy-repro

And basically this is the cypress test:

describe('Start the site', () => {

  it('Starts and works', () => {
    const url = 'http://localhost:3000'
    cy.visit(url)
    cy.get('body.sw-body', {timeout: 10000}).should('exist');
  })
})

Cypress Version

13.15.0

Node version

16.20.0

Operating System

Ubuntu 22.04

Debug Logs

No response

Other

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant