As Roger Wang mentions in his answer, node-webkit does not currently support the Chrome Extension or the Chrome App API's. However, I initially created a Chrome App, and when it was clear that Google was focusing more on the Chrome OS platform than Mac OS and Windows, we made the switch to node-webkit.
To make it easier to port over our Chrome app to node-webkit, I created some API stubs that wrapped around some of the node-webkit, Node.js, and node module APIs that do some of the same things as the Chrome APIs.
Example stubs for chrome.alarms.* APIs:
Here's an example that Stubs out chrome.alarms.* so that it at least doesn't throw errors and silently fails:
window.chrome = {
alarms: {
clear: function(name) {
console.warn("not implemented.");
},
clearAll: function() {
console.warn("not implemented.");
},
create: function(name, obj) {
console.warn("not implemented.");
},
onAlarm: {
addListener: function(callback) {
console.warn("not implemented.");
return;
var alarm = {
name: ""
};
callback();
}
}
}
Example stubs for manifest and background page access:
And here's an example of getting the package.json manifest using chrome.runtime.getManifest, as well as access to a background page in node-webkit via chrome.runtime.getBackgroundPage, assuming the background page opens the window and its parent is the background page:
chrome.runtime: {
getManifest: function() {
return typeof(require) !== "undefined" ? require("../package.json") : {};
},
getBackgroundPage: function(callback) {
var backgroundPage = {
postMessage: function(message, origin) {
if(window.opener != null)
window.opener.postMessage(message, origin);
else
window.postMessage(message, origin);
}
};
callback(backgroundPage);
},
With this solution, we more or less just added a package.json file to the app, added in the API stubs, and had a running app on day 1.
(Disclaimer: This is my open source contribution to node-webkit)
You can find the "node-webkit-chrome-api-stubs" in my GitHub repository.
The code in the GitHub repository actually runs as both a Chrome App as well as a node-webkit app, for demonstration purposes.