-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamically inject variables into scope when added to 'window' sandbox
documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with fix issue: #18
- Loading branch information
1 parent
7e0cd65
commit baedf1e
Showing
7 changed files
with
109 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
window = self = globalThis = unsafeWindow; | ||
|
||
var userscript_wrapper = function(){ | ||
with (window) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
android-studio-project/libs/webview-gm-lib/src/main/res/raw/js_closure_3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
} | ||
} | ||
|
||
userscript_wrapper.call(window) | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ==UserScript== | ||
// @name test: with closure, without sandbox | ||
// @namespace WebViewWM | ||
// @match *://*/* | ||
// @grant none | ||
// @run-at document-end | ||
// ==/UserScript== | ||
|
||
var clean_dom = function() { | ||
while(document.body.childNodes.length) { | ||
document.body.removeChild(document.body.childNodes[0]); | ||
} | ||
} | ||
|
||
var append_to_dom = function(text) { | ||
var div = document.createElement('div'); | ||
var pre = document.createElement('pre'); | ||
var hr = document.createElement('hr'); | ||
|
||
pre.innerText = text; | ||
div.appendChild(pre); | ||
document.body.appendChild(div); | ||
document.body.appendChild(hr); | ||
} | ||
|
||
clean_dom() | ||
append_to_dom(`with closure, without sandbox:\n@grant none`) | ||
|
||
append_to_dom(`(typeof window) = ${(typeof window)}`) | ||
append_to_dom(`(typeof this) = ${(typeof this)}`) | ||
append_to_dom(`(typeof self) = ${(typeof self)}`) | ||
append_to_dom(`(typeof globalThis) = ${(typeof globalThis)}`) | ||
append_to_dom(`(typeof unsafeWindow) = ${(typeof unsafeWindow)}`) | ||
|
||
append_to_dom(`(window === this) = ${(window === this)}`) | ||
append_to_dom(`(window === self) = ${(window === self)}`) | ||
if (typeof globalThis !== 'undefined') | ||
append_to_dom(`(window === globalThis) = ${(window === globalThis)}`) | ||
|
||
append_to_dom(`(window instanceof Window) = ${(window instanceof Window)}`) | ||
|
||
if (typeof unsafeWindow !== 'undefined') { | ||
append_to_dom(`(unsafeWindow instanceof Window) = ${(unsafeWindow instanceof Window)}`) | ||
append_to_dom(`(window === unsafeWindow) = ${(window === unsafeWindow)}`) | ||
} | ||
|
||
append_to_dom(`(typeof GM_info) = ${(typeof GM_info)}`) | ||
append_to_dom(`(typeof window.GM_info) = ${(typeof window.GM_info)}`) | ||
if (typeof unsafeWindow !== 'undefined') | ||
append_to_dom(`(typeof unsafeWindow.GM_info) = ${(typeof unsafeWindow.GM_info)}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters