我正在尝试运行chrome.runtime.sendMessage以从服务器获取信息。我使用这个信息来决定在我的chrome扩展中显示哪个页面。问题是chrome.runtime.sendMessage是一个异步函数,它与app.config不能很好地配合。有没有办法把chrome.runtime.sendMessage变成一个同步函数?
app.config(function($stateProvider, $urlRouterProvider) {
var rootRef = new Firebase(some url);
var user = rootRef.getAuth();
当我创建一个新的选项卡时,下面的脚本是从我的background.js注入的(新选项卡加载一个站点,即Google.com)。
$(function(){
//this fires when tab is created and script injected
chrome.runtime.sendMessage({title: window.document.title}, function(){});
//this fires when clicking on element in created tab
document.getElementById("Usern
我的铬扩展内容脚本使用chrome.runtime.sendMessage向我的后台脚本发送消息,该脚本需要读取cookie并在‘sendResponse’中返回这些信息。代码如下:
ContentScript.js
chrome.runtime.sendMessage({getcookies: "Get me cookies"}, function (response){
console.log(response.cookieList);
});
BackgroundScript.js
var cookiesFinal;
chrome.runtime.onMessag
我在一个循环中为数组中的一堆appIds调用sendMessage。当我的回调被调用时,我需要检查是否有错误,然后将出现错误的appId“列入黑名单”。问题是,我尝试过的每一种方法都会导致回调中的appId在被调用时被更改!因此,错误的appId会被列入黑名单。
我尝试了三个版本(见下文)。一个从不被列入黑名单,另外两个做错了:
**这个黑名单是错的**
for ( var appName in apps )
{
var app = apps[ appName ];
var appId = app[ "appId" ];
//Send message
我正在开发一个chrome扩展,chrome.runtime.sendMessage函数有问题
下面是如何设置我的代码:
chrome.runtime.sendMessage( { method : "getLocalStorage", key: "email" }, function ( response ) {
console.log( "the response has been received" );
});
console.log( "I am here" );
$.ajax({});
这张打印出来:
I