Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Access API without security prompts #3121

Closed
CoenraadS opened this issue Jan 12, 2023 · 4 comments
Closed

File Access API without security prompts #3121

CoenraadS opened this issue Jan 12, 2023 · 4 comments
Assignees
Labels
feature request feature request

Comments

@CoenraadS
Copy link

CoenraadS commented Jan 12, 2023

Is your feature request related to a problem? Please describe.
The user interacts with a webpage that uses window.showDirectoryPicker

After selecting the folder they want, this popup appears:

image

The user then clicks ok, and now the browser has access to this folder

The user then restarts the app

The browser has lost access to the folder (storing the handle doesn't work, permissions are revoked)

The user again has to select the folder, and again the security prompt

Describe the solution you'd like and alternatives you've considered

  1. Some flag I can pass to webview2 such as --disable-file-access-security to disable these popups (automatically accept)

  2. It should also allow a file/directory handle to be reused across app restarts.

Point 1 is most important, point 2 is nice to have

@vickiez
Copy link
Contributor

vickiez commented Jan 20, 2023

Hi @CoenraadS, you can handle the PermissionRequested event and allow requests of this kind: COREWEBVIEW2_PERMISSION_KIND_FILE_READ_WRITE.

Alternatively, if you would like to allow permission for a particular origin, you can try the experimental SetPermissionState API.

@CoenraadS
Copy link
Author

Thanks for the response, but

webView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;

Does not trigger, at least not with the following html:

<!DOCTYPE html>
<html>

<body>
    <div class="fl" style="margin: 0 0 2rem 0"><button id="addToFolder">Give access to folder</button></div>
</body>

</html>

<script>
    const options = {
        mode: 'readwrite'
    }

    document.getElementById('addToFolder').addEventListener('click', async () => {
        try {
            const directory = await window.showDirectoryPicker(options);
            await listFiles(directory);
        } catch (e) {
            console.log(e);
        }
    });

    async function listFiles(directory) {
        for await (const entry of directory.values()) {
            let newEl = document.createElement('div');
            newEl.innerHTML = `<strong>${entry.name}</strong> - ${entry.kind}`;
            document.body.append(newEl);
        }
    }
</script>

@vickiez
Copy link
Contributor

vickiez commented Jan 20, 2023

Oh sorry - we recently added this permission kind to the prerelease SDK, 1.0.1619-prerelease. You can try it now with a preview channel and we will update you when it becomes available in release. :)

@vickiez
Copy link
Contributor

vickiez commented Mar 22, 2023

@CoenraadS this permission kind is now part of the latest release package, 1.0.1661.34. You should now be able to use the PermissionRequested event to handle requests of the kind FileReadWrite. The SetPermissionStateAsync API is also available if you would like to set the permission per origin. Thanks!

@vickiez vickiez closed this as completed Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request
Projects
None yet
Development

No branches or pull requests

2 participants