Skip to content

[BUG] Request made via sendBeacon() inside iframe is not captured when iframe is removed in Firefox #26660

Open
@marian-r

Description

@marian-r

System info

  • Playwright Version: [v1.37.1]
  • Operating System: [All]
  • Browser: [Firefox]
  • Other info:

Source code

  • I provided exact source code that allows reproducing the issue locally.

Config file

// playwright.config.js
const {defineConfig, devices} = require('@playwright/test');

export default defineConfig({
  testDir: './',
  projects: [
    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox']
      }
    },
    {
      name: 'chrome',
      use: {
        ...devices['Desktop Chrome'],
        channel: 'chrome'
      }
    },
    {
      name: 'webkit',
      use: {
        ...devices['Desktop Safari']
      }
    },
  ]
});

Test file (self-contained)

const {test} = require('@playwright/test');

test('test', async ({page}) => {
  await page.setContent(`
<button onclick="requestBeacons()">Request beacons</button>
<iframe id="iframe"></iframe>
<script>
  function requestBeacons() {
    // Send beacon from the top page.
    navigator.sendBeacon('https://httpbin.org/status/204?beacon=0');
    const iframe = document.getElementById('iframe');
    for (let i = 1; i <= 4; i++) {
      // Send beacon from the iframe.
      iframe.contentWindow.navigator.sendBeacon(\`https://httpbin.org/status/204?beacon=\${i}\`);
    }
    document.body.removeChild(iframe);
  } 
</script>  
`);
  
  // Is resolved in all browsers.
  const promise0 = page.waitForRequest('https://httpbin.org/status/204?beacon=0');
  // Times out in Firefox.
  const promise4 = page.waitForRequest('https://httpbin.org/status/204?beacon=4');
  await page.getByText('Request beacons').click();
  await promise0; 
  await promise4;
});

Steps

  • [Run the test]

Expected

Test should pass in all browsers as requests made via sendBeacon() API should be requested even when iframe gets removed.

Actual

The test passes in both Chrome and Webkit, but fails in Firefox. The requests could be seen if the HTML page is loaded in browser manually, but Playwright does not seem to capture the requests made via sendBeacon() in Firefox.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions