w3c / web-share

Web API proposal for sharing data from a web page
https://www.w3.org/TR/web-share/
Other
353 stars 65 forks source link

Sharing files Permission Denied #205

Closed gaboluque closed 3 years ago

gaboluque commented 3 years ago

Hey, I'm sure this should be addressed in another place like StackOverflow, but anyways...

I think there should be more documentation or better error descriptions for this web share api.

I'm trying to share the followeing file

{
  lastModified: 1622843015507
  lastModifiedDate: Fri Jun 04 2021 16:43:35 GMT-0500 (Eastern Standard Time) {}
  name: "60b1d17b7f2cd71c8307fae2"
  size: 37835
  type: "image/png"
  webkitRelativePath: ""
}

I've made sure that the type is a permitted type, but I keep getting DOMException: Permission denied. I really don’t understand what should I be looking for.

ewilligers commented 3 years ago

An implementation might give permission denied errors for a variety of reasons. In a StackOverflow answer, I might mention

gaboluque commented 3 years ago

I guess right now my options are reduced to 1 or 2. Which I've never seen any documentation about. How many files can I share? What is the top size?

I'll keep doing some trial and error, but seems like walking blind.

Thanks for the answer BTW, @ewilligers

tomayac commented 3 years ago

Moving this discussion to StackOverflow, where it started.

beaufortfrancois commented 3 years ago

@gaboluque Does https://stackoverflow.com/a/68314686/422957 work for you?

gaboluque commented 3 years ago

Hey @beaufortfrancois, I couldnt't really grasp the actual error, reducing the image size worked for now, I had to add a restriction for max 200kb, although this is not for overall files size (file1 + file2 + ...) but for single file size.

E.g I can share 5 200kb images but not 1 500kb image

beaufortfrancois commented 3 years ago

According to https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webshare/navigator_share.cc;l=288;drc=eb07aa534eea81dac5aa15e1a8bbd4405bd1fb60;bpv=1;bpt=1, it should log some console errors if it was size related.


constexpr size_t kMaxSharedFileCount = 10;
constexpr uint32_t kMaxSharedFileBytes = 50U * 1024 * 1024;
...

    if (files.size() > kMaxSharedFileCount ||
        total_bytes > kMaxSharedFileBytes) {
      execution_context->AddConsoleMessage(
          mojom::blink::ConsoleMessageSource::kJavaScript,
          mojom::blink::ConsoleMessageLevel::kWarning, "Share too large");
      exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError,
                                        "Permission denied");
      return ScriptPromise();
    }
  }
gaboluque commented 3 years ago

Yess exactly, I get the "Permission denied" error, this is really helpful!