Protos is a small library that preserves the original object definition per each scope (according to the script file URL).
All you need is to add this library as the first script in your HTML page.
<html>
<head>
<title>...</title>
<script src="https://slavikme.github.io/protos/dist/protos-1.0.0-min.js"
type="application/javascript"></script>
...
</head>
<body>
...
</body>
</html>
By default, Protos will monitor automatically all native function of major types: Array
, String
, Number
, Boolean
, Function
, BigInt
, Object
and RegExp
.
If you want to add monitors to other objects, just wrap it with Protos
function.
For example:
Protos(HTMLElement.prototype);
By default, Protos will scope the script files by origin. If you like to change it, the following scope options are available:
The script path in the following examples is
https://sub.example.com:8080/some/dir/file.js?param=value
hostname
- The hostname/domain part of the URL (without port number). E.g. Thesub.example.com
part.origin
- Origin of the URL, including the protocol, the hostanme and the port. E.g. Thehttps://sub.example.com:8080
part.dir
- The whole URL including the full directory path. E.g. Thehttps://sub.example.com:8080/some/dir
part.file
- The whole full filename, directory and the origin. E.g. Thehttps://sub.example.com:8080/some/dir/file.js
part.href
- The whole URL path. E.g. The whole URLhttps://sub.example.com:8080/some/dir/file.js?param=value
.
In order to change it, just pass the scope
parameter to the protos.js
script, with the value as one of the options above.
For example:
<script src="https://slavikme.github.io/protos/dist/protos-1.0.0-min.js?scope=file"
type="application/javascript"></script>
See the example page to view a sample show-case of the library.
You are more than welcome to expand and contribute to this library. Just create a new pull-request in GitHub, and we will go from there.