Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Dart for Chrome Extensions

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';
}
like image 285
Mikael Avatar asked Mar 03 '14 18:03

Mikael


1 Answers

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.

like image 179
Günter Zöchbauer Avatar answered Nov 13 '22 02:11

Günter Zöchbauer