Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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
2.0.0
jsonp
removed form ConfigcallBackName
removed form ConfigremoveScript
changes - script is not removed by default on an errorcallBack
removed form Config - just run code after simpleLoadScript run (eg. console.log
in examples)FAQs
Very simple promise based script and JSONP
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.