Skip to content

Instantly share code, notes, and snippets.

@andigehle
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save andigehle/a09ac9b765097bb84a65 to your computer and use it in GitHub Desktop.

Select an option

Save andigehle/a09ac9b765097bb84a65 to your computer and use it in GitHub Desktop.
Dart chrome extension example: AddListener on Event from chrome.runtime
{
"name": "TestApplication",
"version": "1",
"manifest_version": 2,
"background": {
"page": "testapplication.html",
"persistent": false
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
name: TestApplication
description: A sample Chrome packaged extension
dependencies:
browser: any
//Placed in web/
import 'dart:js';
void main() {
//This doesnt work in js
context['chrome']['runtime']['onMessage'].callMethod('addListener', [onMessageListener]);
//Works:
context.callMethod('alert', ['This works']);
context['console'].callMethod('log', ['And that works']);
}
/**
* Message event handling
*/
void onMessageListener(request, sender, sendResponse) {
print("test");
}
<!-- Placed in web/ -->
<script src="testapplication.dart" type="application/dart"></script>
<script src="packages/browser/dart.js"></script>
@andigehle
Copy link
Copy Markdown
Author

Put testapplication.html, testapplication.dart and manifest.json in the web/ folder.
[Here in Gist folders can't be created :( ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment