Chrome扩展程序在页面操作中显示弹出窗口

时间:2019-01-13 09:53:48

标签: google-chrome-extension

我对chrome扩展浏览器和页面操作感到有些困惑。 我的目标是弹出特定页面。

manifest.json:

{
  "name": "Basic extention",
  "version": "1.0",
  "description": "Extention",
  "permissions": [
    "activeTab", 
    "declarativeContent", 
    "storage",
    "tabs",
    "*://www.google.com/*"  ],  
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },  
  "page_action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "images/icon16.png",
      "32": "images/icon32.png",
      "48": "images/icon64.png",
      "128": "images/icon128.png"
    }
  },
  "icons": {
    "16": "images/icon16.png",
    "32": "images/icon32.png",
    "48": "images/icon64.png",
    "128": "images/icon128.png"
  },
  "manifest_version": 2
}

background.js

'use strict';

chrome.runtime.onInstalled.addListener(function() {

  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    chrome.declarativeContent.onPageChanged.addRules([{
      conditions: [new chrome.declarativeContent.PageStateMatcher({
        pageUrl: {hostEquals: 'https://www.google.com/*'},
      })],
      actions: [new chrome.declarativeContent.ShowPageAction()]
    }]);
  });
}); 

popup.html

<!DOCTYPE html>
<html>
  <head>
    <style>
      body{
        background-color: green;
      }
    </style>      
    <title>Test extention</title>
  </head>
  <body>  
    Test
  </body>
</html>

所以问题是,如果我在清单中使用browser_action,则它可以正常工作,在扩展图标上单击鼠标左键后会显示弹出窗口。但是当我将其更改为page_action时,鼠标左键打开的菜单与鼠标右键相同,没有弹出窗口。

我需要手动触发弹出窗口吗?还是我缺少清单中的某些权限。我将不胜感激。

1 个答案:

答案 0 :(得分:0)

您为nval=number_of_validation_samples//batchz ntrain=number_of_training_samples//batchz ftgen=tgen("training.csv") fvgen=tgen("validation.csv") history = model.fit_generator(ftgen, steps_per_epoch=ntrain, validation_data=fvgen, validation_steps=nval, epochs=number_of_epochs, callbacks=[checkpointer, stopper], verbose=2) 定义了错误的条件。应该在hostEqualshostEqual之间划分以下内容:

scheme

执行此操作后,它应按定义运行。看看https://developer.chrome.com/extensions/declarativeContent

中的“规则”部分