Search code examples
progressive-web-appsservice-workermanifestweb-shareweb-share-target

PWA - Web Share Target "property 'action' ignored, should be within scope of manifest"


My Web Share Target does not work, I get the error "property 'action' ignored, should be within scope of manifest" when my PWA gets installed.

enter image description here

In the manifest.json I have configured the share_target as below:

 "share_target": {
   "action": "/_share-target",
   "enctype": "multipart/form-data",
   "method": "POST",
   "params": {
     "files": [
       ...
     ]
   }
 }

Solution

  • The problem was that my service worker got installed with scope '/myapp/src/'

     navigator.serviceWorker
      .register("service-worker.js", { scope: '/myapp/src/'})
    

    This results in a absolute url https://myusername.github.io/myapp/src/ where the service worker runs.

    But the web share target points to https://myusername.github.io/_share-target because of the leading slash, which is, as the error message states, not in scope of the service worker.

    So the solution was to adjust the mainfest.json by removing the slash from the share target action property.

    "share_target": {
       "action": "_share-target",
       ...
    }
    

    or define the path within the service worker scope:

    "share_target": {
       "action": "/myapp/src/_share-target",
       ...
    }