Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
simple-load-script
Advanced tools
Very simple promise based script loader and JSONP
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript('//code.jquery.com/jquery-2.2.3.js');
console.log(scriptRef); // HTMLScriptElement
} catch (err) {
console.log(err);
}
import simpleLoadScript from 'simple-load-script';
simpleLoadScript('//code.jquery.com/jquery-2.2.3.js')
.then(function (scriptRef) {
console.log(scriptRef);
})
.catch(function (err) {
console.log(err);
});
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript({
url: '//code.jquery.com/jquery-2.2.3.js',
inBody: true,
attrs: { id: 'one', charset: 'UTF-8' },
});
console.log(scriptRef); // HTMLScriptElement inBody with attrs present
} catch (err) {
console.log(err);
}
Runs global callback (window.gmapiready)
import simpleLoadScript from 'simple-load-script';
try {
const scriptRef = await simpleLoadScript('//maps.googleapis.com/maps/api/js?&callback=gmapiready');
console.log(scriptRef); // HTMLScriptElement
} catch (err) {
console.log(err);
}
Runs global callback (window.elo)
var simpleLoadScript = require('simple-load-script');
try {
const scriptRef = await simpleLoadScript({
url: '//api.ipinfodb.com/v3/ip-city/?format=json&callback=elo',
removeScript: true,
});
console.log(scriptRef); // undefined
} catch (err) {
console.log(err);
}
import simpleLoadScript from 'simple-load-script';
try {
const scriptRefs = await simpleLoadScript([
'//maps.googleapis.com/maps/api/js?&callback=gmapiready',
{
url: '//api.ipinfodb.com/v3/ip-city/?format=json&callback=elo',
removeScript: true,
},
'//code.jquery.com/jquery-2.2.3.js',
]);
console.log(scriptRefs); // HTMLScriptElement[]
} catch (err) {
console.log(err);
}
Config | string | (Config | string)[]
interface Config {
url: string;
attrs?: Record<string, string>;
inBody?: boolean;
insertInto?: string | null;
removeScript?: boolean;
}
const defaultConfig = {
url: '',
attrs: {},
inBody: false,
insertInto: null,
removeScript: false,
};
url
- file to append to bodyattrs
- with attributes to append to script tag (charset
, type
, id
, …)inBody
- append to document.body
instead of document.head
insertInto
- CSS selector (an ID, class name, element name, etc.) to insert the script into. Overrides inBody
value.removeScript
- remove script tag after load; it's always removed on an errorCheck files or package.json
FAQs
Very simple promise based script and JSONP
The npm package simple-load-script receives a total of 2,245 weekly downloads. As such, simple-load-script popularity was classified as popular.
We found that simple-load-script demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.