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

find a way to record events from speculationrules #4

Open
chrmod opened this issue Oct 1, 2024 · 0 comments
Open

find a way to record events from speculationrules #4

chrmod opened this issue Oct 1, 2024 · 0 comments

Comments

@chrmod
Copy link
Member

chrmod commented Oct 1, 2024

this scenarior should work, but it does not, as something disables preprendering

import http from 'node:http';

// Works in Chrome only
// Be sure to start Chrome with Preference "net.network_prediction_options" set to 3
export default async function (browser) {
  let server;
  try {
    server = http.createServer(function (_, res) {
      res.write(`
        <html>
        <head>
        <script type="speculationrules">
          {
            "prerender": [
              {
                "urls": ["next.html"],
                "eagerness": "immediate"
              }
            ]
          }
        </script>
        </head>
        <body>
        <h1>0008-speculationrules</h1>
        <a href="/next.html">prerender</a>
        </body>
        </html>
      `);
      res.end();
    }).listen(8080, ()=> {});

    const puppeteerBrowser = await browser.getPuppeteer()
    await browser.call(async () => {
      const [page] = await puppeteerBrowser.pages();
      const client = await page.target().createCDPSession();
      await client.send('Page.setPrerenderingAllowed', { isAllowed: true });
    });

    await browser.navigateTo("http://localhost:8080");
    // TODO: required for Firefox - find something to wait for that will be faster
    await new Promise(r => setTimeout(r, 1000));
  } finally {
    server.closeAllConnections();
    await new Promise(r => server.close(r));
  }
}
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