简体   繁体   English

使用从Chrome控制台中的Chrome扩展程序加载的jQuery

[英]Using jQuery that's loaded from a Chrome extension in Chrome Console

I'm developing a Chrome extension that ships jQuery and jquery is referenced from the manifest.json and works as expected when I reference to it from other JS files in my extension package. 我正在开发一个Chrome扩展程序,该扩展程序附带了jQuery,并且manifest.json中引用了jQuery,并且当我从扩展包中的其他JS文件中引用它时,该扩展程序可以按预期工作。

However from Chrome console, even though I know my extension is loaded jQuery is not accessible 但是从Chrome控制台,即使我知道我的扩展程序已加载,jQuery也无法访问

I tried accessing it like this: 我试图这样访问它:

$('div').append(); etc. or jQuery 等或jQuery

and neither of them works. 而且它们都不起作用。

Not having console with jQuery support hinders the development process a lot. 没有具有jQuery支持的控制台会极大地阻碍开发过程。

I would define your additional content script which would embed jQuery into every page. 我将定义您的其他内容脚本,该脚本会将jQuery嵌入到每个页面中。

manifest.json manifest.json

{
    "name": "Content script",
    "version": "0.1",
    "content_scripts": [{
        "matches": ["http://*/*"],
        "js": ["jquery-loader.js"]
    }]
}

And inside jquery-loader.js : jquery-loader.js内部:

var script = document.createElement('script');
script.src = 'jquery.min.js';
(document.body || document.head).appendChild(script);

This way you would have jQuery on any page. 这样,您将在任何页面上使用jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM