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
- Host: GitHub
- URL: https://github.com/pshihn/no-script
- Owner: pshihn
- License: mit
- Created: 2019-03-11T05:18:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-14T04:23:52.000Z (about 5 years ago)
- Last Synced: 2025-04-15T19:09:35.140Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.