Require.JS in a Chrome extension: define is not defined
There are two contexts in content scripts. One is for browser, another is for extension.
You load require.js into the extension context. But require.js loads dependencies into the browser context. define
is not defined in the browser.
I wrote a (untested) patch about this problem. To use this, load this into extension context after require.js. Your modules will be loaded into extension context. Hope this helps.
require.attach = function (url, context, moduleName, onScriptLoad, type, fetchOnlyFunction) { var xhr; onScriptLoad = onScriptLoad || function () { context.completeLoad(moduleName); }; xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function (e) { if (xhr.readyState === 4 && xhr.status === 200) { eval(xhr.responseText); onScriptLoad(); } }; xhr.send(null);};
The recommended approach now is to use cajon ( https://github.com/requirejs/cajon/ ). See https://groups.google.com/d/msg/requirejs/elU_NYjunRw/3NT9NIFL2GUJ .