gmailr
gmailr copied to clipboard
Random Error: Uncaught ReferenceError: $LAB is not defined
I'm seeing the following error in my console at random times:
Uncaught ReferenceError: $LAB is not defined
It pops from time to time, but most of the time the page is loading properly. Any idea what might be causing this?
I think the way loading happens in bootstrap.js is the culprit. It relies on an asynchronous loading technique to inject both lab.js and init.js, and so it's possible for init.js to be loaded before lab.js is executed:
https://github.com/jamesyu/gmailr/blob/92330b0ca477697e87f56c9518903cb49dbf660d/chrome/lib/bootstrap.js#L40
One thing worth trying is replacing those loadScript
lines with:
// Load the initialization scripts
chrome.extension.sendMessage({ "action": "load_scripts", "payload": [
"lab.js",
"init.js"
]});
Then in a background.js file, add something like:
chrome.extension.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.action === 'load_scripts') {
var scripts = request.payload;
for (var i = 0, ilen = scripts.length; i < ilen; i++) {
chrome.tabs.executeScript(null, { "file": scripts[i] });
}
break;
}
});
I'd submit this as a pull request, but I wanted to check two things first:
- whether there's a less complicated solution (e.g. http://stackoverflow.com/a/2880147/69697 )
- whether there are any security concerns introduced here -- e.g. could files not belonging to the extension be injected here, could remote files be injected here...
The way I got round this is at the very bottom of lab.js I added:
$LAB
.script(document.getElementById("init_path_gcgmailr_data").getAttribute('data-val'))
.wait();
In bootstrap.js I:
addData("init_path", chrome.extension.getURL("lib/init.js"));
// and commented out
//loadScript(chrome.extension.getURL("lib/init.js"));
this seemed to work for me
I think to great extent I gave up on LAB and embedded my javascripts with the Rails asset pipeline into a single huge js. I think another reason this was required was because I may be racing to load with other Gmail plugins like Boomerang which were loading their JS ahead of my LAB's.
On Fri, Nov 22, 2013 at 7:54 AM, Cyapow [email protected] wrote:
The way I got round this is at the very bottom of lab.js I added:
$LAB.script(document.getElementById("init_path_gcgmailr_data").getAttribute('data-val')).wait();
In bootstrap I:
addData("init_path", chrome.extension.getURL("lib/init.js")); // and commented out //loadScript(chrome.extension.getURL("lib/init.js"));
this seemed to work for me
— Reply to this email directly or view it on GitHubhttps://github.com/jamesyu/gmailr/issues/11#issuecomment-29082934 .