An open API service indexing awesome lists of open source software.

https://github.com/pshihn/no-script

custom element that will block all child script elements from executing
https://github.com/pshihn/no-script

Last synced: about 1 month ago
JSON representation

custom element that will block all child script elements from executing

Awesome Lists containing this project

README

        

# no-script

**no-script** is a custom element that will block all child `script` elements from executing.

There may be times when you want to block all script under a specific node, especially when third party code is being injected under that node.

[View the live demo](https://pshihn.github.io/no-script/demo/)

## Example

Consider the following code:

```html

No Script!



console.log('Executed: inline script');





```

Nothing gets logged in the console.
(Both `a.js` and `b.js` also log to the console.)

### Allowing certain scripts

Any script that you want to be allowed to execute, add the attribute `allow-execution` to the `script` tag.

```html


console.log('This will NOT get logged');


console.log('This WILL get logged');

```

## Caveats
`no-script` needs to be defined synchronously in the code, or at least defined before the html in question is parsed.

```html



```

Also, `no-script` relies on mutation observers, which means it's not guaranteed that the browser will not execute the script before firing the observer events. Though, having tested on modern Chrome, Safari, and Firefox, it works.

## Work in progress
This element is result of a different (not-open-source) experiment about controliing execution of third party javascript. I'm extracting the basics into an open web component. Plan is to add some of those features to this element such as enabling/scheduling disabled scripts.