puppeteer overridePermissions clipboard-read not working on createIncognitoBrowserContext()

Viewed 910

The following code is viable for reading the clipboard in headless/headfull:

var context = await client.defaultBrowserContext();
await context.overridePermissions('http://localhost', ['clipboard-read']);
page = await browser.newPage();
await page.goto( 'http://localhost/test/', {waitUntil: 'load', timeout: 35000});
// click button for clipboard..
let clipboard = await page.evaluate(`(async () => await navigator.clipboard.readText())()`);

But when you later start incognito its not working anymore:

const incognito = await client.createIncognitoBrowserContext();
page = await incognito.newPage();

and you get:

  • DOMException: Read permission denied.

I currently try to figure out to combine both.. Anybody know how to set overridePermissions inside of the new incognito window?

Please notice I do not want to use the incognito chrome arg at the start. I want to manually create new incognito pages inside of my scripts with correct overridePermissions.

1 Answers

I am having the very same issue. Here's a minimal reproducible example. Nodejs version: v16.13.1 puppeteer version: puppeteer@14.4.1

  'use strict';
  const puppeteer = require('puppeteer');
  const URL = 'https://google.com';
  (async () => {
      const browser = await puppeteer.launch();
      const context = browser.defaultBrowserContext();
      context.overridePermissions(URL, ['clipboard-read', 'clipboard-write'])
      const page = await browser.newPage();
      await page.goto(URL, {
        waitUntil: 'networkidle2',
      });
  
      await page.evaluate(() => navigator.clipboard.writeText("Injected"));
  
      const value = await page.evaluate(() => navigator.clipboard.readText());
      console.log(value);
  })();
Related