Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Error: Uncaught ReferenceError: $LAB is not defined #11

Open
arbet opened this issue Oct 17, 2012 · 3 comments
Open

Random Error: Uncaught ReferenceError: $LAB is not defined #11

arbet opened this issue Oct 17, 2012 · 3 comments

Comments

@arbet
Copy link

arbet commented Oct 17, 2012

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?

@bregenspan
Copy link

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:

loadScript(chrome.extension.getURL("lib/lab.js"));

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...

@Cyapow
Copy link

Cyapow commented Nov 22, 2013

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

@mikedll
Copy link

mikedll commented Nov 22, 2013

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//issues/11#issuecomment-29082934
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants