{"id":10681,"date":"2023-01-30T17:48:54","date_gmt":"2023-01-30T09:48:54","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10681"},"modified":"2023-01-30T23:17:44","modified_gmt":"2023-01-30T15:17:44","slug":"js-background-services","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2023\/01\/js-background-services\/","title":{"rendered":"Chrome\u6d4f\u89c8\u5668\u539f\u751f\u652f\u6301\u76847\u79cd\u540e\u53f0\u670d\u52a1\u7b80\u4ecb"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10681\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10681<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202301-bg-api.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/cover-hhh.png\" width=\"480\" height=\"306\" alt=\"\u5c01\u9762\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<p>\u5728Chrome\u6d4f\u89c8\u5668\u4e0b\uff0c\u6211\u4eec\u6253\u5f00\u63a7\u5236\u53f0\uff0c\u5207\u6362\u5230 application \u9762\u677f\uff0c\u4f1a\u770b\u5230\u6709\u4e00\u4e2a\u540d\u4e3abackground services\u7684\u5217\u8868\u9879\uff0c\u91cc\u9762\u6709\u4e00\u5806\u770b\u8d77\u6765\u5f88\u9ad8\u7ea7\u7684API\u7279\u6027\uff0c\u5982\u4e0b\u622a\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/20230106-184505-min.png\" width=\"206\" height=\"171\" alt=\"\u540e\u53f0\u670d\u52a1\u622a\u56fe\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4ed6\u4eec\u5206\u522b\u662f\uff08zxx: \u70b9\u51fb\u53ef\u5feb\u901f\u5b9a\u4f4d\uff09\uff1a<\/p>\n<ul>\n<li><a href=\"#backgroundFetch\">Background Fetch<\/a><\/li>\n<li><a href=\"#backgroundSync\">Background Sync<\/a><\/li>\n<li><a href=\"#notification\">Notifications<\/a><\/li>\n<li><a href=\"#paymentHandler\">Payment Handler<\/a><\/li>\n<li><a href=\"#periodicBackground\">Periodic Background Sync<\/a><\/li>\n<li><a href=\"#PushMessaging\">Push Messaging<\/a><\/li>\n<li><a href=\"#reportingApi\">Reporting API<\/a><\/li>\n<\/ul>\n<p>\u597d\u5bb6\u4f19\uff0c\u5927\u90e8\u5206\u90fd\u4e0d\u8ba4\u8bc6\u3002<\/p>\n<p>\u8fd9\u79cd\u611f\u89c9\u5c31\u597d\u50cf\uff0c\u75ab\u60c5\u7ed3\u675f\u7ec8\u4e8e\u53ef\u4ee5\u56de\u8001\u5bb6\u4e86\uff0c\u7ed3\u679c\u6751\u91cc\u9762\u7a81\u7136\u5192\u51fa\u4e86\u5f88\u591a\u4e0d\u8ba4\u8bc6\u7684\u4eba\u3002<\/p>\n<p>\u5b66\u4e60\u77e5\u8bc6\u7b2c\u4e00\u6b65\uff0c\u5148\u4e86\u89e3\uff0c\u6240\u4ee5\uff0c\u672c\u6587\u5c31\u7b80\u5355\u4e86\u89e3\u4e0b\u8fd9\u4e9b\u540e\u53f0\u670d\u52a1\u90fd\u662f\u505a\u4ec0\u4e48\u7528\u7684\uff0c\u89c9\u5f97\u5b9e\u7528\u7684\uff0c\u591a\u82b1\u70b9\u65f6\u95f4\u6df1\u5165\uff0c\u89c9\u5f97\u9e21\u808b\u7684\uff0c\u76f4\u63a5\u4e0d\u6c42\u751a\u89e3\u3002<\/p>\n<h3 id=\"backgroundFetch\">\u4e00\u3001Background Fetch<\/h3>\n<p>Background Fetch API\u662f\u540e\u53f0\u8bf7\u6c42API\uff0c\u5c31\u662f\u6d4f\u89c8\u5668\u5728\u80cc\u540e\u9ed8\u9ed8\u5730\u8bf7\u6c42\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u4e2a\u6bd4\u8f83\u7ecf\u5178\u7684\u5e94\u7528\u573a\u666f\u5c31\u662f\u5927\u6587\u4ef6\u4e0b\u8f7d\u3002<\/p>\n<p>\u662f\u8fd9\u6837\u7684\uff0c\u867d\u7136\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2016\/04\/know-about-html-download-attribute\/\">HTML download\u5c5e\u6027<\/a>\u8fdb\u884c\u6587\u4ef6\u4e0b\u8f7d\uff0c\u6216\u8005\u4f7f\u7528 <a href=\"https:\/\/github.com\/eligrey\/FileSaver.js\/\" rel=\"noopener\" target=\"_blank\">FileSaver.js<\/a> \u8fdb\u884c\u4e0b\u8f7d\uff0c\u4f46\u662f\u5982\u679c\u6587\u4ef6\u975e\u5e38\u5927\uff0c\u4e0b\u8f7d\u5f88\u6162\uff0c\u5219\u4e00\u65e6\u9009\u9879\u5361\u5173\u95ed\uff0c\u6216\u8005\u8bf4\u6d4f\u89c8\u5668\u5173\u95ed\uff0c\u6216\u8005\u8bf4\u7f51\u7edc\u6389\u7ebf\uff0c\u5219\u4e0b\u8f7d\u4efb\u52a1\u5c31\u4f1a\u53d6\u6d88\uff0c\u6216\u8005\u5931\u8d25\u3002<\/p>\n<p>\u867d\u7136\u63a5\u4e0b\u6765\u4f1a\u4ecb\u7ecd\u7684Background Sync API\u63d0\u4f9b\u4e86\u5ef6\u65f6\u670d\u52a1\u7684\u80fd\u529b\uff0c\u4f46\u662f\u8fd9\u4e2a\u80fd\u529b\u5e76\u4e0d\u9002\u5408\u5927\u578b\u6587\u4ef6\u7684\u4e0b\u8f7d\uff0c\u56e0\u4e3aBackground Synchronization API \u7684\u7279\u6027\u6ce8\u5b9a\u4e86\u5176\u5728\u4efb\u52a1\u5b8c\u6210\u524d\u8981\u4fdd\u6301\u6fc0\u6d3b\u7684\u72b6\u6001\uff0c\u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u5b8c\u6210\u9700\u8981\u82b1\u8d39\u5f88\u957f\u65f6\u95f4\uff0c\u5219\u6d4f\u89c8\u5668\u51fa\u4e8e\u8282\u7701\u7535\u6c60\u5bff\u547d\u7b49\u76ee\u7684\u662f\u6709\u53ef\u80fd\u7ec8\u6b62\u6b64\u4efb\u52a1\u7684\u3002<\/p>\n<p>\u800cBackground Fetch API\u5219\u6ca1\u6709\u8fd9\u4e2a\u95ee\u9898\uff0c\u5373\u4f7f\u7528\u6237\u6389\u7ebf\uff0c\u53ea\u8981\u518d\u6b21\u6062\u590d\uff0c\u4e0b\u8f7d\u4efb\u52a1\u4e5f\u4f1a\u7ee7\u7eed\u8fdb\u884c\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u540e\u53f0\u83b7\u53d6API\u8fd8\u53ef\u4ee5\u5728\u524d\u7aef\u5b9e\u65f6\u8fd4\u56de\u4e0b\u8f7d\u8fdb\u5ea6\uff0c\u63d0\u4f9b\u4e86\u4e0b\u8f7d\u7ec8\u6b62\u7684\u80fd\u529b\uff0c\u652f\u6301\u591a\u6587\u4ef6\u6574\u4f53\u4e0b\u8f7d\uff0c\u8fd8\u662f\u5f88\u5f3a\u5927\u7684\u3002<\/p>\n<p>\u6b64API\u9700\u8981\u5728\u5df2\u6ce8\u518c\u7684service worker\u4e2d\u624d\u80fd\u987a\u5229\u6267\u884c\u3002<\/p>\n<p>\u5b98\u65b9\u63d0\u4f9b\u4e86demo\u6f14\u793a\u6848\u4f8b\uff0c\u89c1\uff1a<a href=\"https:\/\/github.com\/WICG\/background-fetch\" rel=\"noopener\" target=\"_blank\">https:\/\/github.com\/WICG\/background-fetch<\/a><\/p>\n<p>\u6211\u770b\u4e86\u4e0b\uff0c\u91cc\u9762\u63d0\u4f9b\u4e86\u4e0d\u9519\u7684\u4f7f\u7528\u793a\u610f\u4ee3\u7801\uff0c\u4f8b\u5982\u70b9\u51fb\u6309\u94ae\u540e\uff0c\u5982\u4f55\u5f00\u542f\u4e00\u4e2a\u540e\u53f0\u4e0b\u8f7d\u7535\u5f71\u6587\u4ef6\uff08MP4\u89c6\u9891\uff09\u529f\u80fd\uff1a<\/p>\n<pre>downloadButton.addEventListener('click', async () => {\r\n  try {\r\n    const movieData = getMovieDataSomehow();\r\n    const reg = await navigator.serviceWorker.ready;\r\n    const bgFetch = await reg.backgroundFetch.fetch(`movie-${movieData.id}`, movieData.urls, {\r\n      icons: movieData.icons,\r\n      title: `Downloading ${movieData.title}`,\r\n      downloadTotal: movieData.downloadTotal\r\n    });\r\n    \/\/ \u524d\u53f0\u6837\u5f0f\u66f4\u65b0\r\n\r\n    bgFetch.addEventListener('progress', () => {\r\n      \/\/ \u524d\u7aef\u4e0b\u8f7d\u8fdb\u5ea6\u663e\u793a\r\n    });\r\n  } catch (err) {\r\n    \/\/ \u663e\u793a\u9519\u8bef\u4fe1\u606f\r\n  }\r\n});<\/pre>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u6b64API\u867d\u7136\u7ed9\u6211\u4eec\u5927\u6587\u4ef6\u4e0b\u8f7d\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u662f\u517c\u5bb9\u6027\u7565\u6709\u5931\u671b\uff0cSafari\u6d4f\u89c8\u5668\u5230\u73b0\u5728\u4e5f\u6ca1\u652f\u6301\uff0c\u54e6\uff0cFirefox\u4e5f\u6ca1\u6709\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_221726.png\" width=\"649\" height=\"247\" alt=\"\u540e\u53f0fetchAPI\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3 id=\"backgroundSync\">\u4e8c\u3001Background Sync<\/h3>\n<p>\u6b64API\u5168\u79f0\u662f Background Synchronization API\uff0c\u4e3b\u8981\u7528\u5728\u79bb\u7ebf\u5f00\u53d1\u573a\u666f\uff0c\u6bd4\u65b9\u8bf4\u624b\u673a\u6389\u7ebf\u7684\u65f6\u5019\uff0c\u8bf7\u6c42\u53ef\u4ee5\u5ef6\u65f6\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u3002<\/p>\n<p>\u4f8b\u5982\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff0c\u5982\u679c\u6389\u7ebf\uff0c\u5927\u90e8\u5206\u7684\u5e94\u7528\u7a0b\u5e8f\u662f\u4f1a\u63d0\u793a\u201c\u7f51\u7edc\u5f02\u5e38\uff0c\u53d1\u9001\u5931\u8d25\u201d\uff0c\u5982\u679c\u4f7f\u7528\u201c\u540e\u53f0\u540c\u6b65API\u201d\uff0c\u90a3\u4e48\u5e94\u7528\u7a0b\u5e8f\u7684\u524d\u7aef\u53ea\u9700\u6ce8\u518c\u4e00\u4e2a\u540c\u6b65\u8bf7\u6c42\uff0c\u5f53\u7f51\u7edc\u518d\u6b21\u51fa\u73b0\u65f6\uff0c\u90ae\u4ef6\u4f1a\u81ea\u52a8\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u3002<\/p>\n<p>\u53ef\u80fd\u662f\u51fa\u4e8e\u4f7f\u7528\u573a\u666f\u7684\u8003\u8651\uff0c\u76ee\u524d\uff0c\u6b64API\u53ea\u80fd\u5728Progressive Web App\uff08\u6e10\u8fdb\u5f0fWeb APP\uff09\u4e2d\u4f7f\u7528\uff0c\u4f9d\u8d56service worker\u8fd0\u884c\u3002<\/p>\n<p>\u800c\u6e10\u8fdb\u5f0fWeb APP N\u5e74\u524d\u6709\u8fc7\u4e00\u9635\u8ba8\u8bba\uff0c\u540e\u6765\uff0c\u611f\u89c9\u5c31\u6de1\u4e86\uff0c\u6240\u4ee5\uff0c\u6211<span style=\"font-size:0;position:absolute;\">\u5f20\u946b\u65ed<\/span>\u611f\u89c9\uff0c\u5927\u591a\u6570\u7684\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u4e00\u8f88\u5b50\u90fd\u4e0d\u4f1a\u7528\u5230\u6b64API\u7684\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>Background Sync\u548cBackground Fetch\u7684\u517c\u5bb9\u6027\u4e00\u6837\uff0c\u76ee\u524d\u4ec5Chrome\u53ca\u5176\u5185\u6838\u6d4f\u89c8\u5668\u652f\u6301\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_222918.png\" width=\"653\" height=\"307\" alt=\"Background Sync\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3 id=\"notification\">\u4e09\u3001Notifications<\/h3>\n<p>Notification\u6307Web\u547c\u8d77\u7cfb\u7edf\u5c42\u9762\u7684\u6d88\u606f\u901a\u77e5\uff0c\u8fd9\u4e2aAPI\u51fa\u73b0\u5df2\u7ecf\u6709\u4e00\u6bb5\u65f6\u95f4\u4e86\u3002<\/p>\n<p>MacOS\u4f1a\u5728\u53f3\u4e0a\u89d2\u663e\u793a\u6d88\u606f\u63d0\u9192\uff08\u5fae\u535a\u5c31\u505a\u4e86\u8fd9\u4e2a\u529f\u80fd\uff09\uff0cWindows\u5219\u5728\u5c4f\u5e55\u7684\u53f3\u4e0b\u89d2\u663e\u793a\u3002<\/p>\n<p>\u6211\u57282016\u5e74\u7684\u65f6\u5019\u66fe\u64b0\u6587\u4ecb\u7ecd\u8fc7\uff0c\u8be6\u89c1\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2016\/07\/know-html5-web-notification\/\">\u7b80\u5355\u4e86\u89e3HTML5\u4e2d\u7684Web Notification\u684c\u9762\u901a\u77e5<\/a>\u201d\u4e00\u6587\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201607\/2016-07-05_220814.png\" width=\"404\" height=\"176\" alt=\"\u5973\u795e\u7684\u56de\u590d\u901a\u77e5\" class=\"alignnone\"><\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>Web Notifications\u7684\u517c\u5bb9\u6027\u8fd8\u662f\u76f8\u5f53\u7ed9\u529b\u7684\uff0c\u662f\u6240\u6709\u80cc\u666f\u670d\u52a1API\u4e2d\u6700\u5b9e\u7528\u7684\u4e00\u4e2a\u7279\u6027\u4e86\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_223156.png\" width=\"656\" height=\"341\" alt=\"Web\u901a\u77e5\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3 id=\"paymentHandler\">\u56db\u3001Payment Handler<\/h3>\n<p>Payment Handler API\u4e3aweb\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e00\u5957\u6807\u51c6\u5316\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u76f4\u63a5\u5904\u7406\u652f\u4ed8\uff0c\u800c\u65e0\u9700\u91cd\u5b9a\u5411\u5230\u5355\u72ec\u7684\u7ad9\u70b9\u8fdb\u884c\u652f\u4ed8\u5904\u7406\u3002<\/p>\n<p>\u8c37\u6b4c\u5b98\u65b9\u63d0\u4f9b\u7684demo\uff1a<a href=\"https:\/\/googlechrome.github.io\/samples\/paymentrequest\/payment-handler\/\" rel=\"noopener\" target=\"_blank\">https:\/\/googlechrome.github.io\/samples\/paymentrequest\/payment-handler\/<\/a><\/p>\n<p>\u6b64API\u53ea\u80fd\u5728HTTPS\u73af\u5883\uff08localhost\u9664\u5916\uff09\u4e0b\u8fd0\u884c\u3002<\/p>\n<p>\u652f\u6301\u662f\u5f88\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u770b\u8d77\u6765\uff0c\u6b64\u529f\u80fd\u4f1a\u975e\u5e38\u5b9e\u7528\uff0c\u53ef\u6839\u636e\u6211\u7684\u4e86\u89e3\uff0c\u6b64API\u53ea\u652f\u6301\u7cfb\u7edf\u5c42\u9762\u7684\u652f\u6301\uff0c\u4f8b\u5982\u5728iPhone\u624b\u673a\u4e2d\uff0c\u53ea\u80fd\u89e6\u53d1Apple Pay\uff0c\u82f9\u679c\u652f\u4ed8\uff0c\u50cf\u662f\u5fae\u4fe1\u652f\u4ed8\u548c\u652f\u4ed8\u5b9d\u662f\u4e0d\u652f\u6301\u7684\u3002<\/p>\n<p>\u539f\u56e0\u5728\u4e8e\uff0c\u65e0\u8bba\u662f\u786c\u4ef6\u3001\u8f6f\u4ef6\u8fd8\u662f\u751f\u6001\u90fd\u662f\u8001\u7f8e\u90a3\u8fb9\u7684\u6807\u51c6\uff0c\u9664\u975e\u54ea\u5929\u8f6f\u4ef6\u56ed\u548c\u64cd\u4f5c\u7cfb\u7edf\u90fd\u662f\u56fd\u4ea7\u7684\uff0c\u90a3\u65f6\u5019\uff0c\u8bf4\u4e0d\u5b9a\u652f\u4ed8\u53ef\u4ee5\u548cWeb\u8f7b\u677e\u96c6\u6210\u3002<\/p>\n<p>\u8bed\u6cd5\u4f7f\u7528\u793a\u610f\uff1a<\/p>\n<pre>var request = null;\r\nif (window.PaymentRequest) {\r\n    request = new PaymentRequest(methods, details, options);\r\n} else {\r\n    \/\/ \u8bd5\u8bd5\u4f7f\u7528\u7279\u5b9a\u652f\u4ed8\u7684jssdk\r\n}<\/pre>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u6b64API\u7684\u517c\u5bb9\u6027\u5c45\u7136\u51fa\u4e4e\u610f\u6599\u7684\u597d\uff0c\u53ef\u60dc\uff0c\u548c\u56fd\u60c5\u4e0d\u7b26\uff0c\u65e0\u6cd5\u672c\u5730\u5316\u4f7f\u7528\uff0c\u5c31\u50cfWeb\u901a\u77e5\uff0cWeb\u5206\u4eab\u8fd9\u6837\u7684\u80fd\u529b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_224030.png\" width=\"654\" height=\"386\" alt=\"\u652f\u4ed8API\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3 id=\"periodicBackground\">\u4e94\u3001Periodic Background Sync<\/h3>\n<p>Periodic Background Sync API\u5141\u8bb8Web\u7f51\u7ad9\u63d0\u9192service worker\u53bb\u5b9a\u65f6\u66f4\u65b0\u67d0\u4e9b\u4fe1\u606f\uff0c\u7528\u9014\u53ef\u80fd\u5305\u62ec\u5728\u8bbe\u5907\u8fde\u63a5\u5230Wi-Fi\u65f6\u83b7\u53d6\u6700\u65b0\u5185\u5bb9\uff0c\u6216\u5141\u8bb8\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u540e\u53f0\u66f4\u65b0\u3002<\/p>\n<p>\u6211\u6478\u4e86\u6478\u6211\u7684\u80e1\u6e23\u60f3\u4e86\u4e0b\uff0c\u8fd9\u4e2aAPI\u6211\u4eec\u65e5\u5e38\u5f00\u53d1\u7528\u5230\u7684\u51e0\u7387\u5f88\u5c0f\uff0c\u5927\u5bb6\u4e86\u89e3\u4e0b\u5373\u53ef\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>Chrome80+\u652f\u6301\uff0cFirefox\u548cSafari\u4e00\u9996\u51c9\u51c9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_224352.png\" width=\"651\" height=\"243\" alt=\"\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3 id=\"PushMessaging\">\u516d\u3001Push Messaging<\/h3>\n<p>\u8fd9\u91cc\u7684Push Messaging\u5e94\u8be5\u6307\u7684\u662fPush API\uff0c\u53ef\u4ee5\u8ba9Web\u5e94\u7528\u6709\u80fd\u529b\u63a5\u53d7\u4ece\u670d\u52a1\u5668\u53d1\u8fc7\u6765\u7684\u6d88\u606f\u3002<\/p>\n<p>\u6b64API\u5e38\u548cNotifications\u4e00\u8d77\u4f7f\u7528\uff0c\u7528\u6765\u5728\u524d\u53f0\u63a8\u9001\u6d88\u606f\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u7531\u4e8e\u6d88\u606f\u63a8\u9001\u5c5e\u4e8e\u654f\u611f\u884c\u4e3a\uff0c\u56e0\u4e3a\uff0c\u6240\u6709\u6d77\u5916\u7684\u90a3\u4e9b\u4fe1\u606f\u63a8\u9001\u670d\u52a1\u5728\u56fd\u5185\u90fd\u662f\u4e0d\u53ef\u7528\u7684\uff08\u9700\u8981\u4f60\u7684\u7535\u8111\u5b89\u88c5\u4e86\u68af\u5b50?\uff09\u3002<\/p>\n<p>\u7136\u540e\uff0c\u56fd\u5185\u6709\u6d4f\u89c8\u5668\u5382\u5546\uff0c\u4f8b\u5982UC\u6d4f\u89c8\u5668\uff0c\u89c6\u56fe\u652f\u6301\u6d88\u606f\u63a8\u9001\uff0c\u4f46\u597d\u50cf\u5728\u5708\u5b50\u91cc\u4e00\u76f4\u662f\u4e0d\u6e29\u4e0d\u706b\u7684\uff0c\u6240\u4ee5\uff0c\u8fd9\u4ef6\u4e8b\u60c5\uff0c\u6211\u89c9\u5f97\u4e5f\u5c31\u8fd9\u6837\u4e86\uff0c\u5f88\u96be\u5927\u8303\u56f4\u666e\u53ca\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u684c\u9762\u7aefSafari\u5728 macOS 13\u53ca\u5176\u4e4b\u540e\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u652f\u6301\uff0c\u79fb\u52a8\u7aefSafari\u5e76\u4e0d\u652f\u6301\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_224617.png\" width=\"652\" height=\"236\" alt=\"Web Push\u652f\u6301\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u80c6\u5b50\u591f\u5927\uff0c\u53ef\u4ee5\u8bd5\u8bd5\u4f7f\u7528push api\u6765\u5224\u65ad\u79fb\u52a8\u7aefSafari\u6d4f\u89c8\u5668\u3002<\/p>\n<h3 id=\"reportingApi\">\u4e03\u3001Reporting API<\/h3>\n<p>Reporting API\u4e3aweb\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e00\u79cd\u901a\u7528\u62a5\u544a\u673a\u5236\uff0c\u4e3b\u8981\u662f\u62a5\u544a\u5e73\u53f0\u7684\u5404\u79cd\u529f\u80fd\uff08\u4f8b\u5982\u5185\u5bb9\u5b89\u5168\u7b56\u7565\u3001\u6743\u9650\u7b56\u7565\u6216\u5f03\u7528\u7684\u529f\u80fd\uff09\u662f\u5426\u53ef\u7528\u3002<\/p>\n<p>\u602a\u4e86\uff0c\u8fd9\u4e2a\u7279\u6027\u6211\u600e\u4e48\u611f\u89c9\u6ca1\u4ec0\u4e48\u7528\u554a\uff1f<\/p>\n<p>\u5982\u679c\u6211\u6709\u8ba4\u8bc6\u4e0a\u7684\u4e0d\u8db3\uff0c\u6216\u8005\u6709\u8c01\u4f7f\u7528\u8fd9\u4e2aAPI\u7684\uff0c\u9ebb\u70e6\u544a\u77e5\u4e0b\u4f7f\u7528\u573a\u666f\u3002<\/p>\n<h4>\u517c\u5bb9\u6027<\/h4>\n<p>\u684c\u9762\u7aefSafari\u770b\u8d77\u6765\u8981\u652f\u6301\u6b64API\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/2023-01-30_225213.png\" width=\"651\" height=\"246\" alt=\"Reporting API\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u516b\u3001\u6587\u6863\u6307\u5f15<\/h3>\n<p>\u6211\u53d1\u73b0\u8fd9\u4e9b\u540e\u53f0API\u5bf9\u5b89\u5168\u8981\u6c42\u8fd8\u633a\u9ad8\u7684\uff0c\u53c8\u8981https\u8ba4\u8bc1\uff0c\u53c8\u8981ServiceWorker\uff0c\u53ef\u5c31\u662f\u8fd9\u4e2a\u5b9e\u7528\u6027\u4e48\uff0c\u4e00\u8a00\u96be\u5c3d\uff0c\u8d44\u6df1\u5f00\u53d1\u4eba\u5458\uff0c\u7279\u6b8a\u5f00\u53d1\u573a\u666f\u624d\u4f1a\u7528\u5230\uff0c\u5bf9\u4e8e\u7edd\u5927\u591a\u6570\u7684\u5f00\u53d1\u8005\u800c\u8a00\uff0c\u7b80\u5355\u4e86\u89e3\u4e0b\uff0c\u77e5\u9053Web\u6709\u8fd9\u4e9b\u6084\u54aa\u54aa\u7684\u80fd\u529b\u5c31\u597d\u4e86\u3002<\/p>\n<p><strong>MDN\u6587\u6863\u6307\u5f15<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Background_Fetch_API\" rel=\"noopener\" target=\"_mdn\">Background Fetch API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Background_Synchronization_API\" rel=\"noopener\" target=\"_mdn\">Background Synchronization API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Notifications_API\" rel=\"noopener\" target=\"_mdn\">Notifications API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Payment_Handler_API\" rel=\"noopener\" target=\"_mdn\">Payment Handler API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_Periodic_Background_Synchronization_API\" rel=\"noopener\" target=\"_mdn\">Web Periodic Background Synchronization API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Push_API\" rel=\"noopener\" target=\"_mdn\">Push API<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Reporting_API\" rel=\"noopener\" target=\"_mdn\">Reporting API<\/a><\/li>\n<\/ul>\n<p>\u597d\uff0c\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u5168\u90e8\u5185\u5bb9\uff0c\u7531\u4e8e\u8fd9\u4e9bAPI\u6211\u4e5f\u662f\u7565\u77e5\u4e00\u4e8c\uff0c\u6240\u4ee5\u53ef\u80fd\u4f1a\u6709\u7406\u89e3\u4e0d\u51c6\u786e\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u65a7\u6b63\uff0c\u4e0d\u751a\u611f\u8c22\uff01<\/p>\n<p>???<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10681\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10681<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202301\/cover-hhh.png\" width=\"160\" height=\"102\" alt=\"\u5c01\u9762\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u5988\u5440\uff0c\u4e0d\u77e5\u4e0d\u89c9\u4e2d\uff0c\u6d4f\u89c8\u5668\u7adf\u7136\u652f\u6301\u4e86\u8fd9\u4e48\u591a\u7684Web\u540e\u53f0\u670d\u52a1\u7279\u6027\uff0c\u4e0d\u5c11API\u6211\u8fd8\u662f\u7b2c\u4e00\u6b21\u89c1\u5230\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[1896,1051,1148,1070,1895,1894,1143],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10681"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10681"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10681\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}