Skip to content

jsPrepend

Inserts the specified content before the existing response body. (This only works for responses with content-type containing javascript and a status code containing a body (e.g., 200/500).)

⚠️ Note: Requests without a body, such as 204 and 304 responses, are not affected.

Rule Syntax

txt
pattern jsPrepend://value [filters...]
ParametersDescriptionDetailed Documentation
patternAn expression to match against the request URLMatch Pattern Documentation
valueText or binary content. Supports the following types:
• Directory/File Path
• Remote URL
• Inline/Embedded/Values Content
Operation Instruction Documentation
filtersOptional filters. Supports matching:
• Request URL/Method/Headers/Content
• Response Status Code/Headers
Filter Documentation

Configuration Example

Inline Method

txt
www.example.com/path1 jsPrepend://(Hello) file://(-test-)
www.example.com/path2 jsPrepend://(Hello) file://(-test-) resType://js
www.example.com/path3 jsPrepend://(Hello) file://(-test-) resType://css
  • Request https://www.example.com/path1/to. The response content becomes
    html
    <!DOCTYPE html>
    <script>Hello</script>-test-
  • Request https://www.example.com/path2/to. The response content becomes Hello-test-
  • Request The response content of https://www.example.com/path3/to becomes -test-

Embedded/Values Method

txt
``` body.txt
Hello world.
```
www.example.com/path1 jsPrepend://{body.txt} file://(-test-)
www.example.com/path2 jsPrepend://{body.txt} file://(-test-) resType://js
www.example.com/path3 jsPrepend://{body.txt} file://(-test-) resType://css
  • Requesting https://www.example.com/path1/to, the response content becomes
    html
    <!DOCTYPE html>
    <script>Hello world.</script> -test-
  • Requesting https://www.example.com/path2/to, the response content becomes Hello world.-test-
  • Request https://www.example.com/path3/to. The response content becomes -test-.

Local/Remote Resources

txt
www.example.com/path1 jsPrepend:///User/xxx/test.js
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js
# Editing a temporary file
www.example.com/path3 jsPrepend://temp/blank.js

Set <script> Tag Attributes for Injected Scripts

Scripts injected into HTML pages via jsPrepend are automatically wrapped in <script> tags by Whistle. To set additional attributes for these tags—such as nomodule, module, defer, async, or crossorigin—you can use the lineProps parameter for configuration.

txt
www.example.com/path1 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://nomodule
www.example.com/path2 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://module
www.example.com/path3 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://defer
www.example.com/path4 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://async
www.example.com/path5 jsPrepend://https://www.xxx.com/xxx/params.js lineProps://crossorigin

Attribute Descriptions and Examples

AttributePurposeConfiguration Example
nomoduleExecutes in traditional browsers; this script will run in browsers that do not support ES modules.lineProps://nomodule
moduleDeclares the script as an ES module, enabling modular imports.lineProps://module
deferLoads asynchronously and executes after the document has been parsed.lineProps://defer
asyncLoads asynchronously and executes immediately after download.lineProps://async
crossoriginEnables Cross-Origin Resource Sharing (CORS) mode.lineProps://crossorigin
  1. Inject content before the response content (Prepend To Body): resPrepend
  2. Inject HTML content before the response content (Prepend HTML To Body, response type must be text/html): htmlPrepend
  3. Inject CSS content before the response content (Prepend CSS To Body, response type must be text/html or text/css): cssPrepend
  4. Inject JS content before the response content (Prepend JS To Body, response type must be text/html, text/css, or application/javascript): jsPrepend
  5. Replace the response content (Replace Body): resBody
  6. Replace the response content with HTML content (Replace Body, response type must be text/html): htmlBody
  7. Replace the response content with CSS content (Replace Body, response type must be text/html or text/css): cssBody
  8. Replace the response content with JS content (Replace Body, response type must be text/html, text/css, or application/javascript): jsBody
  9. Append content after the response content (Append To Body): resAppend
  10. Append HTML content after the response content (Append HTML To Body, response type must be text/html): htmlAppend
  11. Append CSS content after the response content (Append CSS To Body, response type must be text/html or text/css): cssAppend
  12. Append JS content after the response content (Append JS To Body, response type must be text/html, text/css, or application/javascript): jsAppend
  13. Replace the response content using keywords or regular expressions (Modify Body Text): resReplace
  14. Override JSON/Form objects in the response content (Modify Form/JSON): resMerge
  15. Delete a property from a JSON/Form object in the response content (Delete Form/JSON): delete://resBody.xxx