cancel
Showing results for 
Search instead for 
Did you mean: 

Watermarking web content with TrafficScript

Having described Watermarking PDF documents with Stingray and Java and Watermarking Images with Java Extensions, this article describes the much simpler task of adding a watermark to an HTML document.

 

Stingray's TrafficScript language is fully capable of managing text content, so there's no need to revert to a more complex Java Extension to modify a web page:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Only process text/html responses 
$ct = http.getResponseHeader( "Content-Type" ); 
if( ! string.startsWith( $ct, "text/html" ) ) break; 
   
# Calculate the watermark text 
$text = "Hello, world!"
   
# A new style, named watermark, that defines how the watermark text should be displayed: 
$style = ' 
<style type="text/css"
.watermark { 
   color: #d0d0d0; 
   font-size: 100pt; 
   -webkit-transform: rotate(-45deg); 
   -moz-transform: rotate(-45deg); 
   -o-transform: rotate(-45deg); 
   transform: rotate(-45deg); 
   position: absolute; 
   width: 100%; 
   height: 100%; 
   margin: 0; 
   z-index: 100; 
   top:200px; 
   left:25%; 
   opacity: .5; 
</style>'; 
   
# A div that contains the watermark text 
$div = '<div class="watermark">' . $text . '</div>'
   
# Imprint in the body of the document 
$body = http.getResponseBody(); 
if( string.regexmatch( $body, "^(.*)</body>(.*?)$", "i" ) ) { 
   http.setResponseBody( $1 . $style . $div . "</body>" . $2 ); 
- See more at: https://splash.riverbed.com/docs/DOC-1664#sthash.BsuXFRP2.dpuf

 

This rule has the following effect...:

Screen Shot 2013-03-20 at 12.29.13.pngOf course, you can easily change the watermark text:

 

1
$watermark = "Hello, world!";

 

... perhaps to add more debugging or instrumentation  to the page.

 

The CSS style for the watermark is based on this article, and other conversations on stackoverflow; you'll probably need to adapt it to get precisely the effect that you want.

 

This rule uses a simple technique to append text to an HTML document (see the Tracking user activity with Google Analytics article for another example). You could use it to perform other page transforms, such as the common attempt to apply copy-protection by putting a full-size transparent layer over the entire HTML document.

Version history
Revision #:
2 of 2
Last update:
‎01-12-2021 05:16:PM
Updated by:
 
Labels (1)
Contributors