I'm trying to create a Chrome extension using Dart.
As of now I can't get it to run any javascript in the extension, although I can do pub build and run it in a browser.
I have the following 3 files:
Manifest.json:
{
"manifest_version": 2,
"name": "ecDownloader",
"description": "-",
"version": "0.1",
"browser_action": {
"default_title": "Click to disable extension",
"default_icon": "images/icon.png"
},
"options_page" : "options.html"
}
options.html:
<html>
<head>
<meta charset="utf-8">
<title>ecDownloader</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<h1>Options</h1>
<fieldset name="info">
<legend>Login Information</legend>
<label for="username">Username</label>
<input type="text" name="username" id="username" size="20">
<label for="password">Password</label>
<input type="password" name="password" id="password" size="20">
<button type="button">Save!</button>
</fieldset>
<span id="test"></span>
</div>
<script type="application/dart" src="options.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
options.dart:
import 'dart:html';
void main() {
querySelector('#test').text = 'test';
}
A Chrome extension needs to use the CSP compliant script. The CSP compliant scripts are automatically generated by pub build with the extension dart.precompiled.js
but the HTML file references the non-CSP compliant file by default.
There are plans that a configuration option of the Dart2JS transformer should set the link to the appropriate script file, but this is not yet implemented.
There is also an option csp: true
for the Polymer transformer which must be set when Polymer is used.
EDIT
A transformer was added to chrome.dart which does this automatically on pub build
- will be available soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With