grafana / xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/browser/
GNU Affero General Public License v3.0
336 stars 42 forks source link

Panics and errors when `clearPermissions` called on a `BrowserContext` #443

Open ankur22 opened 2 years ago

ankur22 commented 2 years ago

When clearPermissions is called on BrowserContext it panics and fails to clear the cookies ending with the following error:

unable to clear override permissions: invalid context

The javascript test used was:

import { sleep } from 'k6';
import launcher from 'k6/x/browser';

export default function () {
  const browser = launcher.launch('chromium', {
      headless: false,
  });
  const context = browser.newContext({
    permissions: ['geolocation'],
  });
  const page = context.newPage();
  const res = page.goto('https://test.k6.io/browser.php');
  context.clearPermissions();

  sleep(10);
  browser.close();
}

The expected result is that it clears the cookies for all pages that were opened from the relevant context.

The Playwright test code is:

// @ts-check
const { test, chromium } = require('@playwright/test');

test.describe('Editing', () => {
  test('Type login creds', async () => {
    const browser = await chromium.launch({ headless: false, slowMo: 500 });
    const ctx = await browser.newContext({
      permissions: ['geolocation'],
    });
    const page = await ctx.newPage();
    await page.goto('https://test.k6.io/browser.php');
    await ctx.clearPermissions();

    await new Promise(resolve => setTimeout(resolve, 10000));

    await browser.close();
  });
});
### Tasks
- [x] PRs: https://github.com/grafana/xk6-browser/pull/1077, https://github.com/grafana/xk6-browser/pull/1075, https://github.com/grafana/xk6-browser/pull/1076
- [x] Docs: https://github.com/grafana/k6-docs/pull/1379
- [x] TypeDefs: https://github.com/grafana/k6-DefinitelyTyped/pull/17
- [x] Release Notes: https://github.com/grafana/k6/pull/3412
inancgumus commented 1 year ago

Possibly related: #442