Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble debugging content scripts in a chrome extension using require.js
    primarykey
    data
    text
    <p>To load modules in the content scripts I'm using the following code (source <a href="http://prezi.com/rodnyr5awftr/requirejs-in-chrome-extensions/" rel="nofollow noreferrer">http://prezi.com/rodnyr5awftr/requirejs-in-chrome-extensions/</a>):</p> <pre><code>require.load = function (context, moduleName, url) { var xhr; xhr = new XMLHttpRequest(); xhr.open("GET", chrome.extension.getURL(url) + '?r=' + new Date().getTime(), true); xhr.onreadystatechange = function (e) { if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) { eval(xhr.responseText); context.completeLoad(moduleName) } }; xhr.send(null); }; </code></pre> <p>The trouble happens when debugging via the Chrome console. Whenever there is an error in one of my modules it just reports the error occurred in an anonymous function but doesn't inform me which require.js module or line in that module the error occurred but instead always points back to the eval line in the above script.</p> <p>Since a lot of people seem to being using different variations of the above code when using require.js with chrome extensions, there must be a simple way to get more information in the debugging console, I just don't what that is :).</p> <p>Thanks for your help!!</p> <p><strong>UPDATE 4/1:</strong> Changing the eval() statement above to use Function() seems to have solved the problem in that the chrome console adds in the addition information. (credit for this work around goes to this <a href="https://stackoverflow.com/questions/6684046/javascript-eval-method">question</a>).</p> <p>I realize the two functions aren't totally interchangeable (see <a href="https://stackoverflow.com/questions/4599857/is-eval-and-new-function-the-same-thing">this question</a>). If anyone is aware of any pitfalls in using Function() instead of eval() in the above code please let me know!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload