Anyone have an idea of how to access the 'require'...
# suitescript
j
Anyone have an idea of how to access the 'require' method in a Chrome Extension. Trying a little pet project to get some 2.0 modules loaded in an extension to see what I can do with em but got stuck on the dreaded 'require is not defined' reference error.
d
I use this snippet to load the modules:
Copy code
require([
    'N/record',
    'N/runtime',
    'N/search',
    'N/query',
    'N/email',
    'N/https'

], function (
    record,
    runtime,
    search,
    query,
    email,
    https

) {
    window['record'] = record;
    window['runtime'] = runtime;
    window['search'] = search;
    window['query'] = query;
    window['email'] = email;
    window['https'] = https

})
🦆 1
pretty handy
j
Copy code
let script = document.createElement('script');
script.id = 'netsuite-load-require';
script.innerHTML = setTimeout(function () {
    var record, currentRecord, search;
    //load modules
    console.log('Check entry and 3 second delay');
    require(['N/record', 'N/currentRecord', 'N/search'], function (r, c, s) {
        //when loaded assign back to variables
        record = r;
        currentRecord = c;
        search = s;
        console.log("2.0 record/currentRecord/search modules loaded")
    });
}, 3000);
(document.head || document.documentElement).appendChild(script);
My still not working inject code block 😞
Works in console.... does not work when called from extension
s
Ask @michoel
My extension is open source have a look at how I inject code into DOM by adding a script tag
If you are still stuck let me know, I'm happy to help
j
Thanks, @michoel. Appreciate the help (and the extension which I use frequently)
j
I'm stuck on something similar. I want to put my require-modules-snippet into a TamperMonkey script so it loads on appropriate pages but doesn't work. Would love to not have to paste it into the console each time.