在Chrome扩展内容脚本中使用Dart不会运行? [英] Using Dart in Chrome extension content script does not run?

查看:261
本文介绍了在Chrome扩展内容脚本中使用Dart不会运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Dart编写Chrome扩充功能。到目前为止一切都很好,除了内容脚本 - 内容脚本dart文件中的主功能似乎没有运行。



更具体地说,首先Dartium不能使用,因为在清单中的js规则中提供一个dart文件导致Dartium抱怨;我接下来试图编译dart文件(使用csp:true),然后使清单包含编译的js文件直接---然后我被卡住了,似乎无论我尝试,(编译)主



更新:



$ b b $ b

清单文件:

  {
manifest_version: 2,
name:Assistant,
description:帮助你完成各种任务,
version:1.0,
minimum_chrome_version :26.0,
permissions:[< all_urls>,storage],

content_scripts:[
{
matches :[< all_urls>],
js:[
packages / browser / dart.js,
dart_content_script.dart.js
] ,
run_at:document_start,
all_frames:false
}
],

browser_action:{
default_popup:popup.html,
default_icon:bulb.png
},

background:{
page background.html
}
}

内容脚本dart文件:

  void main(){
print('main done');
}

pubspec.yaml:

  name:AssistentExtension 

依赖项:
浏览器:任何
chrome:any

dev_dependencies:
unittest:'> = 0.10.0'

变压器:
- $ dart2js:
csp:true

在Chrome开发者控制台中,我可以找到字符串main done,意味着main在编译的js中,但没有打印意味着它不运行。

解决方案

当时我查看控制台日志,一个日志说chrome包丢失(但我不知道是什么原因),所以我手动添加回到构建文件夹,然后它的工作我可以看到我的日志写在main()。



当我执行 test_ext ,其中包含 官方Chrome pub ,我在控制台日志中得到了不同的错误消息,我再次解决了它,然后 test_ext 示例也运行良好。



所以,我的建议是看看控制台日志,它可能有所帮助。您可以通过右键点击扩展程序弹出式窗口UI 打开控制台扩展程序,然后选择检查元素将其打开。


I am trying to write a Chrome extension using Dart. So far everything goes well except for the content script --- the "main" function in the content script dart file does not seem to run.

To be more specific, first of all Dartium cannot be used since giving a dart file in the "js" rule in the manifest caused Dartium to complain; I next tried to compile the dart file (with csp: true) then make the manifest to include the compiled js file directly --- then I'm stuck, it seems that no matter what I try, the (compiled) "main" function just does not run.

Any suggestions?

Update:

The manifest file:

{
  "manifest_version": 2,
  "name": "Assistant",
  "description": "Assists you with various tasks.",
  "version": "1.0",
  "minimum_chrome_version": "26.0",
  "permissions": ["<all_urls>", "storage"],

  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": [
        "packages/browser/dart.js",
        "dart_content_script.dart.js"
      ],
      "run_at": "document_start",
      "all_frames": false
    }
  ],

  "browser_action": {
    "default_popup": "popup.html",
    "default_icon": "bulb.png"
  },

  "background": {
    "page": "background.html"
  }
}

The content script dart file:

void main() {
  print('main done');
}

The pubspec.yaml:

name: AssistentExtension

dependencies:
  browser: any
  chrome: any

dev_dependencies:
  unittest: '>=0.10.0'

transformers:
- $dart2js:
    csp: true

In the Chrome developer console, I can find the string "main done" meaning that the "main" function is indeed included in the compiled js, but nothing is printed meaning it is not run.

解决方案

I had the same problem like yours. At that time I looked into the console logs, a log saying chrome package is missing (but i don't know what cause it), so I manually added it back to build folder, then it worked so I can see my logs written in main().

When I run test_ext that come with official chrome pub, I get a different error message in console log, again I solved it and then the test_ext sample is running well too.

So, my advise is take a look at the console log, it might help. You can open console for extension by right click on popup UI of extension and select 'Inspect Element' to open it.

这篇关于在Chrome扩展内容脚本中使用Dart不会运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆