我无法从Chrome扩展程序发出通知。我知道我们不能直接从内容脚本触发它,这就是我在 background.js 文件中有通知代码的原因。但是,这仍然无效。我需要您的帮助,以确定如何显示Chrome扩展程序中的通知。
内容脚本:
{
"name": "test",
"version": "0.0.1",
"manifest_version": 2,
"description": "xdsfds",
"author": "Miraj",
"background": {
"scripts" : ["background.js"],
"persistent" : false
},
"content_scripts": [
{
"matches": ["https://google.com/*","file:///*/Desktop/extensionPage.html"],
"js": ["/js/lib/jquery-3.1.1.min.js",
"/js/lib/bootstrap.min.js",
"/js/lib/angular.min.js",
"/js/lib/idbstore.js",
"/js/contentScript.js",
"/js/angJs/main.js",
"/js/angJs/communiqueService.js",
"/js/angJs/commTrackerDir.js"],
"css": ["/css/sforce.css",
"/css/main.css"]
}
],
"web_accessible_resources": [
"/templates/*"
],
"permissions": [
"cookies",
"unlimitedStorage",
"notifications"
]
}
Background.js
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
alert('i am listening'); //this is getting invoked
var opt = {
type: "basic",
title: "Primary Title",
message: "Primary message to display",
iconUrl: '/images/notification.png'
};
chrome.notifications.create(new Date().getTime(), opt, function(rs){
alert(rs);
});
sendResponse({returnMsg: "All good!"}); // optional response
});
ContentScript.js
chrome.extension.sendMessage({msg: "Sup?"}, function(response) {
// optional callback - gets response
console.log(response);
});
答案 0 :(得分:0)
RSpec::Core::MultipleExceptionError: Connection refused (java.net.ConnectException)
Connection refused (java.net.ConnectException)
Connection refused (java.net.ConnectException)
Connection refused (java.net.ConnectException)
1 example, 1 failure, 0 passed
Finished in 13.649753594 seconds
[remote server] java.net.PlainSocketImpl(PlainSocketImpl.java):-2:in `socketConnect': Connection refused (java.net.ConnectException) (Selenium::WebDriver::Error::UnknownError)
from [remote server] java.net.AbstractPlainSocketImpl(AbstractPlainSocketImpl.java):350:in `doConnect'
from [remote server] java.net.AbstractPlainSocketImpl(AbstractPlainSocketImpl.java):206:in `connectToAddress'
from [remote server] java.net.AbstractPlainSocketImpl(AbstractPlainSocketImpl.java):188:in `connect'
from [remote server] java.net.SocksSocketImpl(SocksSocketImpl.java):392:in `connect'
from [remote server] java.net.Socket(Socket.java):589:in `connect'
from [remote server] org.apache.http.conn.socket.PlainConnectionSocketFactory(PlainConnectionSocketFactory.java):74:in `connectSocket'
from [remote server] org.apache.http.impl.conn.DefaultHttpClientConnectionOperator(DefaultHttpClientConnectionOperator.java):141:in `connect'
from [remote server] org.apache.http.impl.conn.PoolingHttpClientConnectionManager(PoolingHttpClientConnectionManager.java):353:in `connect'
from [remote server] org.apache.http.impl.execchain.MainClientExec(MainClientExec.java):380:in `establishRoute'
from [remote server] org.apache.http.impl.execchain.MainClientExec(MainClientExec.java):236:in `execute'
from [remote server] org.apache.http.impl.execchain.ProtocolExec(ProtocolExec.java):184:in `execute'
from [remote server] org.apache.http.impl.execchain.RetryExec(RetryExec.java):88:in `execute'
from [remote server] org.apache.http.impl.execchain.RedirectExec(RedirectExec.java):110:in `execute'
from [remote server] org.apache.http.impl.client.InternalHttpClient(InternalHttpClient.java):184:in `doExecute'
from [remote server] org.apache.http.impl.client.CloseableHttpClient(CloseableHttpClient.java):71:in `execute'
from [remote server] org.apache.http.impl.client.CloseableHttpClient(CloseableHttpClient.java):55:in `execute'
from [remote server] org.openqa.selenium.remote.internal.ApacheHttpClient(ApacheHttpClient.java):142:in `fallBackExecute'
from [remote server] org.openqa.selenium.remote.internal.ApacheHttpClient(ApacheHttpClient.java):88:in `execute'
from [remote server] org.openqa.selenium.remote.HttpCommandExecutor(HttpCommandExecutor.java):160:in `execute'
from [remote server] org.openqa.selenium.remote.service.DriverCommandExecutor(DriverCommandExecutor.java):82:in `execute'
from [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):601:in `execute'
from [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):658:in `execute'
from [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):497:in `quit'
from [remote server] sun.reflect.GeneratedMethodAccessor56():-1:in `invoke'
from [remote server] sun.reflect.DelegatingMethodAccessorImpl(DelegatingMethodAccessorImpl.java):43:in `invoke'
from [remote server] java.lang.reflect.Method(Method.java):498:in `invoke'
from [remote server] org.openqa.selenium.support.events.EventFiringWebDriver$2(EventFiringWebDriver.java):103:in `invoke'
from [remote server] com.sun.proxy.$Proxy4():-1:in `quit'
from [remote server] org.openqa.selenium.support.events.EventFiringWebDriver(EventFiringWebDriver.java):201:in `quit'
from [remote server] org.openqa.selenium.remote.server.handler.DeleteSession(DeleteSession.java):50:in `call'
from [remote server] org.openqa.selenium.remote.server.handler.DeleteSession(DeleteSession.java):29:in `call'
from [remote server] java.util.concurrent.FutureTask(FutureTask.java):266:in `run'
from [remote server] org.openqa.selenium.remote.server.DefaultSession$1(DefaultSession.java):176:in `run'
from [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecutor.java):1142:in `runWorker'
from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPoolExecutor.java):617:in `run'
from [remote server] java.lang.Thread(Thread.java):745:in `run'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/response.rb:70:in `assert_ok'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/curb.rb:78:in `request'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:649:in `raw_execute'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:627:in `execute'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/remote/bridge.rb:220:in `quit'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/chrome/bridge.rb:68:in `quit'
from /home/user/.rvm/gems/ruby-2.3.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/driver.rb:175:in `quit'
from /home/user/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/selenium/driver.rb:241:in `quit'
from /home/user/.rvm/gems/ruby-2.3.0/gems/capybara-2.7.1/lib/capybara/selenium/driver.rb:20:in `block in browser'
的第一个参数应该是一个字符串。 chrome.notifications.create
返回一个整数。您可以使用new Date().getTime()
将其转换为字符串。