playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Support permissions for chromium File System Access API

Open kepta opened this issue 3 years ago • 17 comments

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.

kepta avatar Oct 22 '22 17:10 kepta

I really need this in playwright!

lubobill1990 avatar Apr 05 '23 18:04 lubobill1990

Likewise, I would benefit from this as well!

zalo avatar Apr 12 '23 18:04 zalo

I would also love this feature. :pray:

sepehr500 avatar Apr 24 '23 23:04 sepehr500

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]))

zalo avatar Apr 25 '23 00:04 zalo

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.

Yesterday17 avatar Apr 25 '23 03:04 Yesterday17

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

bildungsroman avatar Jun 09 '23 23:06 bildungsroman

I need this too! 🙏

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

darkvertex avatar Nov 19 '23 05:11 darkvertex

I need this feature

hevilhuy avatar Jul 21 '24 09:07 hevilhuy

+1 would be awesome if Playwright supported these APIs

alvaromartmart avatar Jul 25 '24 09:07 alvaromartmart

also need

dpmillerau avatar Sep 23 '24 05:09 dpmillerau

how long do you intend to "collect feedback" for..?

GamerGirlandCo avatar Oct 23 '24 21:10 GamerGirlandCo

how long do you intend to "collect feedback" for..?

Why is it that github.com is filling up with more and more people complaining about how long tickets have been open for? The sense of entitlement is simply embarrassing. I guess we should go back to a world of only paid, proprietary software?

huyz avatar Oct 24 '24 01:10 huyz

how long do you intend to "collect feedback" for..?

Why is it that github.com is filling up with more and more people complaining about how long tickets have been open for? The sense of entitlement is simply embarrassing. I guess we should go back to a world of only paid, proprietary software?

oh. i'm sorry for not commenting "+1" like everyfuckingone else 🥴

GamerGirlandCo avatar Oct 24 '24 17:10 GamerGirlandCo

Are there any news if or when this could be supported? I'm also eagerly waiting for playwright to support this.

jibow avatar Oct 28 '24 15:10 jibow

For those having the issue, I have implemented a workaround on my app. Instead of providing the FileSystemHandle using showDirectoryPicker, I load a zip (with an input type file) of the test folder that I unzip, and I load all the files into the navigator.storage.getDirectory and then I provide this FileSystemHandle to the rest of the code. It works greatly.

Amatewasu avatar Oct 28 '24 16:10 Amatewasu

like @Amatewasu mentioning, this works as temporary solution if instance of FileSystemFileHandle is needed. (like on my case)

let fsDir: FileSystemDirectoryHandle;
let fsStoreFileHandle: FileSystemFileHandle;

beforeAll(async () => {
  fsDir = await navigator.storage.getDirectory();
  fsStoreFileHandle = await fsDir.getFileHandle('some.file', {create: true});
});

mharj avatar Feb 21 '25 10:02 mharj

this is really important. building any kind of complex browser-based editor/tool relies on this API.. please support

lifeinchords avatar Jun 19 '25 19:06 lifeinchords

It would be very useful to have built-in support (or a recommended way) to mock these APIs. Is this planned?

Thanks

TheAngularGuy avatar Aug 21 '25 12:08 TheAngularGuy