Last active
August 29, 2015 14:05
-
-
Save andigehle/a09ac9b765097bb84a65 to your computer and use it in GitHub Desktop.
Dart chrome extension example: AddListener on Event from chrome.runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "TestApplication", | |
| "version": "1", | |
| "manifest_version": 2, | |
| "background": { | |
| "page": "testapplication.html", | |
| "persistent": false | |
| }, | |
| "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: TestApplication | |
| description: A sample Chrome packaged extension | |
| dependencies: | |
| browser: any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Placed in web/ --> | |
| <script src="testapplication.dart" type="application/dart"></script> | |
| <script src="packages/browser/dart.js"></script> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put testapplication.html, testapplication.dart and manifest.json in the web/ folder.
[Here in Gist folders can't be created :( ]