microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.68k stars 3.58k forks source link

[Feature] Support permissions for chromium File System Access API #18267

Open kepta opened 1 year ago

kepta commented 1 year ago

I am the author of bangle-io - a library which allows taking note locally thanks to the File System Access API.

Currently Playwright doesn't support accepting permissions (see the screenshot) to view/edit a local file using the following api.

let dirHandle = await window.showDirectoryPicker();
const perms = await dirHandle.requestPermission(opts);

image

Do you think others might benefit from this as well?

This will benefit folks writing robust apps which provide local first support.

lubobill1990 commented 1 year ago

I really need this in playwright!

zalo commented 1 year ago

Likewise, I would benefit from this as well!

sepehr500 commented 1 year ago

I would also love this feature. :pray:

zalo commented 1 year ago

For intrepid future travelers, I bypassed this by evaling a function that returns a list of filenames and base64 encoded bytes from blobs.

In the browser page:

async function blobToBase64(blob) {
  return new Promise((resolve, _) => {
    let reader = new FileReader();
    reader.onloadend = () => resolve(reader.result.split(',')[1]);
    reader.readAsDataURL(blob);
  });
}

window.getFilesAsB64 = async function () {
  // Get a list of filenames and a list of blobs somehow
  let files = {};
  for (let i = 0; i < blobs.length; i++) {
    files[filenames[i]] = await blobToBase64(blobs[i]);
  }
  return files;
}

In the playwright-python app:

files = await page.evaluate("window.getFilesAsB64()")
for filename in files:
    with open("./"+filename, "wb") as binary_file:
        binary_file.write(base64.b64decode(files[filename]))
Yesterday17 commented 1 year ago

For intrepid future travelers, I bypassed this by evaling a function that returns a list of filenames and base64 encoded bytes from blobs.

It's not a workaround for this issue, but a workaround for file writing. In fact, we want permission support for FileSystem Access API just because we are using this API and want to test programs relying on this. If we just want to read/write files, we can use workarounds instead.

bildungsroman commented 1 year ago

This would really come in handy for my team as well. Our app relies heavily on the FSA API

darkvertex commented 10 months ago

I need this too! 🙏

I bet the Microsoft devs behind https://vscode.dev (which uses the Filesystem API) would appreciate it also.

hevilhuy commented 1 month ago

I need this feature

alvaromartmart commented 1 month ago

+1 would be awesome if Playwright supported these APIs