Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 以下链接时,内容\脚本未在GitHub上运行_Google Chrome Extension_Content Script - Fatal编程技术网

Google chrome extension 以下链接时,内容\脚本未在GitHub上运行

Google chrome extension 以下链接时,内容\脚本未在GitHub上运行,google-chrome-extension,content-script,Google Chrome Extension,Content Script,我正在为Github Enterprise上的Pull请求编写一个Chrome扩展,遇到了一个问题。当通过刷新或直接输入浏览器中的url加载页面时,页面会运行;当通过单击Github中的链接运行页面时,页面不会运行 例如,如果您使用转到此页面并单击其中一个页面,它将不会运行。但如果刷新同一页,它将运行 manifest.json { "name": "Github Sample", "manifest_version": 2, "version": "0.0.1",

我正在为Github Enterprise上的Pull请求编写一个Chrome扩展,遇到了一个问题。当通过刷新或直接输入浏览器中的url加载页面时,页面会运行;当通过单击Github中的链接运行页面时,页面不会运行

例如,如果您使用转到此页面并单击其中一个页面,它将不会运行。但如果刷新同一页,它将运行

manifest.json

{
    "name": "Github Sample",
    "manifest_version": 2,
    "version": "0.0.1",
    "description": "Sample",
    "permissions": [
        "tabs", "<all_urls>",
        "http://github.com/*"
    ],
    "content_scripts": [
        {
            "matches": [ "https://github.com/*" ],
            "js": ["github.sample.js"],
            "run_at": "document_end"
        }
    ]
}
为了让这更容易,我把它推到了

关于如何解决这个问题,您有什么想法吗?

GitHub站点使用库(请参阅)

  • 基本上,您只需要运行一次内容脚本并在其中附加pjax事件处理程序,它将重用站点的
    jQuery
    $
    变量

    • 在这些处理程序中,您可以向内容脚本发送带有
      document.dispatchEvent
      的消息,该脚本将在其
      窗口中接收该消息。addEventListener(“blabla”,…)
    • 或者您可以在github站点的
      manifest.json
      中,这样页面注入的代码将能够发送一条消息,该消息可由
      chrome.runtime.onMessageExternal
      侦听器中的扩展接收
  • 或者,您可以在后台脚本中使用,但这会在安装过程中导致警告,即扩展可以“读取您的浏览历史记录”,这是一种与内容脚本解决方案不同的全局权限

GitHub站点使用库(请参阅)

  • 基本上,您只需要运行一次内容脚本并在其中附加pjax事件处理程序,它将重用站点的
    jQuery
    $
    变量

    • 在这些处理程序中,您可以向内容脚本发送带有
      document.dispatchEvent
      的消息,该脚本将在其
      窗口中接收该消息。addEventListener(“blabla”,…)
    • 或者您可以在github站点的
      manifest.json
      中,这样页面注入的代码将能够发送一条消息,该消息可由
      chrome.runtime.onMessageExternal
      侦听器中的扩展接收
  • 或者,您可以在后台脚本中使用,但这会在安装过程中导致警告,即扩展可以“读取您的浏览历史记录”,这是一种与内容脚本解决方案不同的全局权限


我提出的工作示例,以防对其他人有所帮助

manifest.json

{
    "name": "Github Sample",
    "manifest_version": 2,
    "version": "0.0.1",
    "description": "Sample",
    "permissions": [
        "activeTab",
        "tabs", "<all_urls>",
        "http://github.com/*"
    ],
    "content_scripts": [
        {
            "matches": [ "https://github.com/*" ],
            "js": ["github.sample.js"],
            "run_at": "document_idle"
        }
    ],
    "web_accessible_resources": ["inject.js"]
}
inject.js

$(document).on('pjax:success', function() {
  var evt=document.createEvent("CustomEvent");
    evt.initCustomEvent("pageLoadTransition", true, true, null);
    document.dispatchEvent(evt);
})

我还用工作示例更新了Github存储库。

我提出的工作示例,以防对其他人有所帮助

manifest.json

{
    "name": "Github Sample",
    "manifest_version": 2,
    "version": "0.0.1",
    "description": "Sample",
    "permissions": [
        "activeTab",
        "tabs", "<all_urls>",
        "http://github.com/*"
    ],
    "content_scripts": [
        {
            "matches": [ "https://github.com/*" ],
            "js": ["github.sample.js"],
            "run_at": "document_idle"
        }
    ],
    "web_accessible_resources": ["inject.js"]
}
inject.js

$(document).on('pjax:success', function() {
  var evt=document.createEvent("CustomEvent");
    evt.initCustomEvent("pageLoadTransition", true, true, null);
    document.dispatchEvent(evt);
})

我还使用工作示例更新了Github存储库。

谢谢,我认为这使我现在朝着正确的方向前进。再次感谢,我能够使用您的解释来实现它。再次感谢,我认为这使我现在朝着正确的方向前进。再次感谢,我能够使用您的解释来实现它。