You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -724,11 +735,16 @@ To achieve this, the static entry HTML has to be __Encoded__ at build time by `h
724
735
?f.apply(thisArg, args)
725
736
:f(...args);
726
737
}
727
-
</script>
738
+
</script><!--<C!-- end of mandatory no-hook scripts --C>
739
+
<C!-- comment --C>
740
+
<script src="..."></script>
728
741
...
729
742
</html>-->
730
743
```
731
744
745
+
-`</head></html>` is inserted between the first `hook.min.js` script and the second no-hook script, which looks strange but is required for correct execution of no-hook scripts.
746
+
- If `</head></html>` is inserted at the end of mandatory no-hook scripts according to the normal HTML format, the page encounters the unexpected "hook is not defined" error, whose root cause is under investigation.
747
+
732
748
## Supported Syntax
733
749
734
750
- Functions
@@ -790,6 +806,7 @@ To achieve this, the static entry HTML has to be __Encoded__ at build time by `h
790
806
-`hookPrefix`: Prefix for `hook.global()._p_GlobalVariable` proxy accessors. Default: `_p_`
791
807
- Note: `hook.global()` return the global object with `get/set` accessors for the prefixed name
-`hook.__hook__(f: function or string, thisArg: object, args: Array, context: string, newTarget: new.target meta property)`
795
812
- minimal hook callback function with property hooking
@@ -837,6 +854,13 @@ To achieve this, the static entry HTML has to be __Encoded__ at build time by `h
837
854
-`cachedMethodDebug(astPath: Array)`: context as `'script.js,Class,Method'`, comparing contexts with those by "oldMethod" in console.warn() messages
838
855
-`oldMethod(astPath: Array)`: context as `'script.js,Class,Method'` for compatibility
839
856
- custom context generator function has to be added to this object with its unique contextGeneratorName
857
+
-`hook.$(symbolToContext = __hook__, contexts)`: context symbol generator function used in hooked scripts to generate symbols corresponding to given contexts
858
+
- Example call inserted at the beginning of a hooked script: `const __context_mapper__ = $hook$.$(__hook__, [ 'examples/example2.js,C', ... ]);`
859
+
-`__context_mapper__`: `Array` of symbol contexts
860
+
- In a hooked script, `__context_mapper__` is actually `__ + hex(sha256(topContextOfScript + code)) + __`
861
+
- Note: Due to this specification, **the same script in the same URL cannot be loaded to a single document multiple times**
862
+
-`__context_mapper__[N]`: the symbol context corresponding to the string context `contexts[N]`
863
+
-`__hook__[__context_mapper__[N]]` is set as `contexts[N]` so that `__hook__` can convert symbol contexts to their corresponding string contexts
840
864
- Hooked Native APIs: Automatically applied in `hook()` preprocessing
841
865
-`hook.global(hookCallback: function = hookName, context: string, name: string, type: string)._p_name`: hooked global variable accessor when `hookGlobal` is true
842
866
-`type`: one of `'var', 'function', 'let', 'const', 'class', 'get', 'set', 'delete', 'typeof'`
@@ -969,6 +993,8 @@ To achieve this, the static entry HTML has to be __Encoded__ at build time by `h
969
993
-`cors=true` parameter: CORS script, e.g., `<script src="https://cross.origin.host/path/script.js?cors=true"></script>`
970
994
-`hook.serviceWorkerTransformers`:
971
995
-`encodeHtml(html: string)`: encode HTML for Service Worker
996
+
-`<!-- end of mandatory no-hook scripts -->`: insert this exact marker as a comment so that all mandatory no-hook scripts before the marker in the HTML of the entry document can be executed even at the first load without Service Worker
997
+
- Note: `no-hook-authorization` hashes are NOT effective at the first load
972
998
-`decodeHtml(html: string)`: decode encoded HTML for Service Worker
973
999
-`hook.hookWorkerHandler(event)`: onmessage handler for Hook Workers
974
1000
- Usage: `onmessage = hook.hookWorkerHandler` in Hook Worker script
@@ -981,6 +1007,157 @@ To achieve this, the static entry HTML has to be __Encoded__ at build time by `h
981
1007
-`createHash`: Synchronous SHA hash generator collections from [sha.js](https://github.com/crypto-browserify/sha.js)
982
1008
-`HTMLParser`: HTML parser from [htmlparser2](https://www.npmjs.com/package/htmlparser2)
983
1009
1010
+
## Plugins
1011
+
1012
+
- Plugins are no-hook scripts for enhancements
1013
+
- Currently, they are configured for the demo application under `demo/`, but fully customizable for any target applications
- Generate `cache-bundle.json` from `caches` and upload the data to saveURL (`errorReport.json`) if the entry page is invoked with `?cache-bundle=save` parameter
1073
+
- The server must be `npm run upload` with `cacheBundleUploadService.js` to receive and save `cache-bundle.json`
- Note: `Math` object properties must be wrapped with `wrapGlobalProperty` function
1149
+
1150
+
#### Notes on Performance Overheads on Global Object Access
1151
+
1152
+
- There are significant access performance overheads on global objects due to wrapped property getter/setter functions
1153
+
- To mitigate the overheads, define local alias objects for frequently used global objects
1154
+
- For example, `const URL = window.URL, RegExp = window.RegExp, ...`
1155
+
- Internal Details on the overheads:
1156
+
- If `contextStack` is empty, the global object is accessed outside of hooked scripts and thus `new Error().stack` has to be analyzed, which is an extremely heavy operation
1157
+
- If `contextStack` is not empty, the global object is accessed within a hooked script, whose access can be controlled via ACL
1158
+
-`contextStack` operations are relatively lightweight without performance degradation on deep call stack
1159
+
- If local alias objects are defined, the corresponding global object access is performed only once per object, whose overheads are insignificant
0 commit comments