我有一个Chrome扩展程序,可以通过浏览器操作点击来切换侧边栏.侧边栏包含带有本地(Chrome扩展程序)源的iframe.我认为iframe中的页面将被视为本地chrome扩展文件,可以打开访问chrome API等.但是,我在Web控制台中不断收到以下错误:
未捕获的TypeError:无法读取未定义< - background.js的属性'onClicked'
TypeError:无法读取undefined < - sidebar.js的属性'query'
如何获取它以便使用上下文脚本注入的iframe可以访问本地chrome环境?
代码如下:
sidebar.js:
var myApp = angular.module('PlaceMates', []);
myApp.service('pageInfoService', function() {
this.getInfo = function(callback) {
var model = {};
chrome.tabs.query({
'active': true, // Select active tabs
lastFocusedWindow: true // In the current window
},
function (tabs) {
if (tabs.length > 0)
{
model.title = tabs[0].title;
model.url = tabs[0].url;
chrome.tabs.sendMessage(tabs[0].id, { 'action': 'PageInfo' }, function (response) {
model.pageInfos = response;
console.log("popup js: " + model.pageInfos);
callback(model);
});
}
});
}; …Run Code Online (Sandbox Code Playgroud) javascript iframe google-chrome-extension content-script angularjs