replace-outbound-value
The replace-outbound-value
snippet overrides return values of functions or attributes according to the given parameters.
Parameters
method
The method to trap. This could be any function or attribute that is accessible under window. e.g. JSON.stringify, atob
...
Yes
n.a.
search
The text or regex pattern to replace
Yes
n.a.
replacement
The replacement text
No
empty string
decodeMethod
The decode method. When provided the snippet can decode the encoded text before replacing it. Useful for functions like btoa. Currently only “base64” is supported.
No
empty string
path
Dot-separated path to the property in returned objects. Can be used to override return values for functions that return objects instead of primitive strings. If left empty, only functions that return strings will be tackled. e.g. user.profile.name.
No
empty string
stack
Comma-separated list of strings to check in the stack trace. If provided the replacement will only apply when the stack trace contains at least one of these patterns.
No
empty string
Filter examples
replace-outbound-value 'JSON.stringify' '"ads":true' '"ads":false'
window.testData = { user: "john", ads: true }; const res = JSON.stringify(window.testData);
res
will have ads: false
replace-outbound-value 'testObj.getText' '/first.*second/' ''
window.testObj = { getText: () => "Anything between first" + "and second will be removed." }; console.log(window.testObj.getText());
Should print "Anything between will be removed"
replace-outbound-value 'btoa' 'ads' 'content' 'base64'
const encoded1 = btoa("This text contains ads"); const encoded2 = btoa("This text contains content"); console.log(encoded1 === encoded2);
Encoded should have the base64 encoded version of "This text contains content"
replace-outbound-value 'testObj.getData' 'premium' 'basic' '' 'user.profile.name'
window.testObj = { getData: () => ({ user: { profile: { name: "John premium", status: "premium_user" }, settings: { theme: "premium_theme" } }, config: { ads: "premium_ads" } }) }; console.log(window.testObj.getData())
user.profile.name will be John basic. Rest of the premium values should not be changed.
replace-outbound-value 'testObj.getText' 'ads' 'content' '' '' 'callerFunction'
window.testObj = { getText: () => "Contains ads" }; window.callerFunction = function callerFunction() { return window.testObj.getText(); }; window.otherCallerFunction = function otherCallerFunction() { return window.testObj.getText(); };
It should return "Contains content" when callerFunction is called, it should return “Contains ads” when otherCallerFunction is called.
Last updated
Was this helpful?