feat: support for Web Worker env issue #124
This commit is contained in:
8
dist/xss.js
vendored
8
dist/xss.js
vendored
@@ -448,6 +448,14 @@ if (typeof window !== "undefined") {
|
||||
window.filterXSS = module.exports;
|
||||
}
|
||||
|
||||
// using `xss` on the WebWorker, output `filterXSS` to the globals
|
||||
function isWorkerEnv() {
|
||||
return typeof self !== 'undefined' && self instanceof DedicatedWorkerGlobalScope;
|
||||
}
|
||||
if (isWorkerEnv()) {
|
||||
self.filterXSS = module.exports;
|
||||
}
|
||||
|
||||
},{"./default":1,"./parser":3,"./xss":5}],3:[function(require,module,exports){
|
||||
/**
|
||||
* Simple HTML Parser
|
||||
|
||||
2
dist/xss.min.js
vendored
2
dist/xss.min.js
vendored
File diff suppressed because one or more lines are too long
19
example/web.html
Normal file
19
example/web.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Test xss.js</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
<script src="../dist//xss.js"></script>
|
||||
<script>
|
||||
document.querySelector('body').innerText = filterXSS('<a href="#" onclick="alert(/xss/)">click me</a>');
|
||||
</script>
|
||||
|
||||
</html>
|
||||
25
example/webworker.html
Normal file
25
example/webworker.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Test xss.js</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
if (window.Worker) {
|
||||
var myWorker = new Worker('worker.js');
|
||||
myWorker.onmessage = function (e) {
|
||||
document.querySelector('body').innerText = e.data;
|
||||
};
|
||||
} else {
|
||||
alert('Your browser does not support Worker');
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
||||
3
example/worker.js
Normal file
3
example/worker.js
Normal file
@@ -0,0 +1,3 @@
|
||||
importScripts("../dist/xss.js");
|
||||
|
||||
postMessage(filterXSS('<a href="#" onclick="alert(/xss/)">click me</a>'));
|
||||
@@ -29,3 +29,11 @@ for (var i in parser) exports[i] = parser[i];
|
||||
if (typeof window !== "undefined") {
|
||||
window.filterXSS = module.exports;
|
||||
}
|
||||
|
||||
// using `xss` on the WebWorker, output `filterXSS` to the globals
|
||||
function isWorkerEnv() {
|
||||
return typeof self !== 'undefined' && self instanceof DedicatedWorkerGlobalScope;
|
||||
}
|
||||
if (isWorkerEnv()) {
|
||||
self.filterXSS = module.exports;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user