Javascript 为什么我的chrome扩展';s pageAction.js不返回活动选项卡URL或标题

Javascript 为什么我的chrome扩展';s pageAction.js不返回活动选项卡URL或标题,javascript,jquery,google-chrome,google-chrome-extension,Javascript,Jquery,Google Chrome,Google Chrome Extension,我正在Windows 10中进行页面操作扩展,Chrome版本为48.0.2564.82 m manifest.json { "manifest_version": 2, // using 2, as instructed by google "name": "my page action :) ", "version": "1.0", "permissions": [ "activeTab", // active tabs

我正在Windows 10中进行页面操作扩展,Chrome版本为48.0.2564.82 m

manifest.json

{
    "manifest_version": 2,       // using 2, as instructed by google
    "name": "my page action :) ",
    "version": "1.0",
    "permissions": [
        "activeTab",       // active tabs are permitted
        "https://www.google.com/"    // oddly, my icon appears on any site not just google
    ],
        "page_action": {
        "default_title": "my page action extension :) ",
        "default_icon": "bookmark20grey.png",
        "default_popup": "popup.htm"       // source below
    },
    "background": {
        "scripts": ["background.js"],     // using background script as per documentation
        "persistent": false
    }
}
background.js

chrome.tabs.onUpdated.addListener(function(id, info, tab){
    chrome.pageAction.show(tab.id);
    chrome.tabs.executeScript(null, {"file": "pageaction.js"}); // injecting code to page
});
$(function(){

    var funx = {
        getCurrentTab : function(){ // using deferreds for function sequencing purposes later
            return new Promise(function(resolve, reject){
                chrome.tabs.query(
                    {
                        active:true,
                        lastFocusedWindow:true
                    },
                    function(tabs){
                        console.log(tabs[0].url); // shows undefined
                        console.log(tabs[0].title); // shows undefined
                        resolve(tabs[0]);
                    }
                );
            });
        }
    }

    funx.getCurrentTab()
        .then(function(tab){
            console.log(tab); // gives me correct tab info, but it's devoid of title and url
        })
    ;


});
popup.htm

这就像一个常规的扩展一样好(图标在位置栏之外),但我正试图将其转换为特定域的页面操作

预期结果 如果我在弹出窗口上单击鼠标右键(当它是常规扩展时)并进行检查,我会看到控制台日志,并显示一个对象:

active: true
audible: false
favIconUrl: "http://cdn.sstatic.net/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"
height: 979
highlighted: true
id: 38
incognito: false
index: 5
mutedInfo: Object
pinned: false
selected: true
status: "complete"
title: "why does my chrome extension's pageAction.js not return the active tab URL or title - Stack Overflow"
url: "http://stackoverflow.com/questions/ask"
width: 1683
windowId: 6
但是,当我将其作为页面操作运行并检查弹出窗口时,我得到以下结果:

active: true
audible: false
height: 979
highlighted: true
id: 38
incognito: false
index: 5
mutedInfo: Object
pinned: false
selected: true
status: "complete"
width: 1683
windowId: 6
active: true
audible: false
height: 979
highlighted: true
id: 38
incognito: false
index: 5
mutedInfo: Object
pinned: false
selected: true
status: "complete"
width: 1683
windowId: 6