0

deskotp 알림에 크롬 확장을 사용합니다. 나는 이렇게 할 수있다 - 사용자가 추천 한 페이지를 방문하면 보여줄 것이다.탭이있는 크롬 확장 알림

background.js

function show() { 
    var notification = window.webkitNotifications.createNotification(
    '48.png', 
    'YOUR VISIT PAGE http://stackoverflow.com/!' 
); 
    notification.show(); 
} 

// Conditionally initialize the options. 
if (!localStorage.isInitialized) { 
    localStorage.isActivated = true; // The display activation. 
    localStorage.frequency = 1;  // The display frequency, in minutes. 
    localStorage.isInitialized = true; // The option initialization. 
} 


function checkForValidUrl(tabId, changeInfo, tab) { 
    if (tab.url.indexOf('stackoverflow') > -1) { 
    if (window.webkitNotifications) { 
     if (JSON.parse(localStorage.isActivated)) { 
      show(); 
     } 
    } 
    } 
} 


chrome.tabs.onUpdated.addListener(checkForValidUrl); 

manifest.json을

{ 
    "name": "YouVisit", 
    "version": "0.1", 
    "description": 
    "Show desktop notification when user visit page", 
    "icons": {"48": "48.png"}, 
    "permissions": [ 
    "notifications", 
    "tabs" 
    ], 
    "background": { "scripts": ["background.js"] }, 
    "manifest_version": 2, 

    "web_accessible_resources": [ 
    "48.png" 
    ] 
} 

이 코드가 작동하지 않는 이유는 어떤 아이디어? 누군가가 저에게 적절한 문학 작품을 줄 수 있습니까?

따르면 the docs에 :

// Create a simple text notification: 
var notification = webkitNotifications.createNotification(
    '48.png',   // icon url - can be relative 
    'Hello!',   // notification title 
    'Lorem ipsum...' // notification body text 
); 
+0

가 작동하지 않습니다 무슨 일 – abraham

+0

localStorage 대신 [chrome.storage.sync] (https://developer.chrome.com/extensions/storage)를 사용해야하며 [Chrome 확장 프로그램 알림] (https://developer.chrome.com/ 확장/알림) (사용자에게 허가를 요구하는) webkitNotifications 대신 (특별한 허가가 필요하지 않은) (https://developer.chrome.com/extensions/permission_warnings#nowarning). –

답변

1

당신은 createNotification() 기능에 대한 적절한 인수를 제공하는 데 실패? 오류 세부 사항을 포함시켜야합니다.
관련 문제