How to get your PWA to show up next to native apps in system-level sharing UIs
TheWeb Share Target APIlets you display yourProgressive Web Appin a user’s native sharesheetafter it’s been installed. While it works great if you have a server available to receive the request, it’s much harder to get working if you don’t.
In this article we’ll useWorkbox, a set of JavaScript libraries for adding offline support to web apps, to create a share target URL that lives entirely inside yourservice worker. This lets static sites and single-page apps serve as share targets without a dedicated server endpoint.
System-level share target picker with an installed PWA called
#“share_target”(****************************: ****************************{
**************“action”************************: “/ share”********************************************************************
"method"(****************************:**************** POST**************, (********************************"enctype"(****************************:“multipart / form-data”,********************************************************
… ****************************************"method"(****************************:**************** POST**************, (********************************"enctype"(****************************:“multipart / form-data”,********************************************************
“params”
(****************************:{****************************)******************************"title"
(****************************: **************************name ", (****************************** () **************************"text"******************************“description” ,****************************files ":
[
{
"name":"photos",
"accept":["image/jpeg",".jpg"] ************** ()(****************************** () ************************** ****************************}]**************************************************************(************************************************************ ...While normally handled by a server endpoint, a neat trick you can do for a share target is to register a route directly in your service worker to handle the request. This will let your app be a share target without a backend.
You do this inWorkboxby registering a route that's handled by your service worker. Start by importing
registerRoute from 'workbox-routing' . Notice that it's registered for the / share route, the same one listed in the example web app manifest. In response it calls shareTargetHandler ()
. import {registerRoute }fromworkbox-routing ' ;************************** (**************************** (**********************************************registerRoute (, (****************************** () **************************** shareTargetHandler****************************/ share ', ********Read More
GIPHY App Key not set. Please check settings