小编Gad*_*med的帖子

Chrome Service Worker 推送通知仅在我网站的选项卡 URL 关闭或不活动时显示

我想仅当我的网站中没有打开的 chrome 选项卡或选项卡已打开且未选择(活动)时才显示 GCM 服务工作线程消息。

\n\n

这是我的代码。

\n\n

错误: chrome 未定义(\xe2\x80\xa6)。

\n\n

清单.json

\n\n
 {  \n  "name": "Webplus Express",  \n  "short_name": "Webplus Express",  \n  "icons": [{  \n    "src": "https://raw.githubusercontent.com/deanhume/typography/gh-pages/icons/typography.png",  \n    "sizes": "192x192",\n    "type": "image/png" \n    }],  \n    "start_url": "/index.html",  \n    "display": "standalone",  \n    "gcm_sender_id": "298340340811",\n    "gcm_user_visible_only": true,\n    "background": {\n    "scripts": ["service-worker.js"]\n    },    \n    "permissions": [\n    "gcm","tabs","activeTab"\n    ]  \n  }\n
Run Code Online (Sandbox Code Playgroud)\n\n

service-worker.js

\n\n
    // The service worker running in background to receive the incoming\n// push notifications and user clicks\nself.addEventListener(\'push\', function(event) { …
Run Code Online (Sandbox Code Playgroud)

service google-chrome worker push-notification google-cloud-messaging

5
推荐指数
1
解决办法
4941
查看次数