aboutsummaryrefslogtreecommitdiffstats
path: root/doc/manual/html_node/JavaScript-Detection.html
blob: c4c858587a5e793570bc04ef9762fa44ba866772 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is for GNU LibreJS (version 6.0.10.20151022, 22 October 2015),
a GNU IceCat extension to detect and block nonfree nontrivial
JavaScript on webpages.

Copyright (C) 2011 2012 2014 2015 Loic J. Duros

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts.  A copy of the license is included in the section entitled
"GNU Free Documentation License". -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU LibreJS 6.0.10.20151022: JavaScript Detection</title>

<meta name="description" content="GNU LibreJS 6.0.10.20151022: JavaScript Detection">
<meta name="keywords" content="GNU LibreJS 6.0.10.20151022: JavaScript Detection">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="index.html#Top" rel="up" title="Top">
<link href="Free-Licenses-Detection.html#Free-Licenses-Detection" rel="next" title="Free Licenses Detection">
<link href="How-to-Use.html#How-to-Use" rel="prev" title="How to Use">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="JavaScript-Detection"></a>
<div class="header">
<p>
Next: <a href="Free-Licenses-Detection.html#Free-Licenses-Detection" accesskey="n" rel="next">Free Licenses Detection</a>, Previous: <a href="How-to-Use.html#How-to-Use" accesskey="p" rel="prev">How to Use</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>
<hr>
<a name="JavaScript-Detection-1"></a>
<h2 class="chapter">5 JavaScript Detection</h2>
<a name="index-javascript"></a>

<ul>
<li>LibreJS considers JavaScript on a page nontrivial if any of the
following are true:

</li><li> It makes an AJAX request or is loaded along with scripts that make
an AJAX request,

</li><li> It loads external scripts dynamically or is loaded along with
scripts that do,

</li><li> It defines functions or methods and either loads an external script
(from HTML) or is loaded as one,

</li><li> It uses dynamic JavaScript constructs that are difficult to analyze
without interpreting the program or is loaded along with scripts
that use such constructs. These constructs are:
<ul>
<li> Using the eval function
</li><li> Calling methods with the square bracket notation
</li><li> Using any other construct than a string literal with certain methods
(<code>Obj.write</code>, <code>Obj.createElement</code>, &hellip;).
</li></ul>
</li></ul>

<p>In practice, the JavaScript code in your page may be found trivial by
LibreJS if, as a whole:
</p><ul>
<li> It does not define functions and it does not load external scripts
(with the HTML src attribute in a <code>&lt;script&gt;</code> tag).

</li><li> It does not make AJAX calls.

</li><li> It does not load external scripts with dynamic constructs.

</li><li> It does not use constructs that may be used to do any of the above in
a non-obvious way (use of the <code>eval()</code> method, use of square bracket
method calls, use of concatenation with certain constructs or method
calls, &hellip;).

</li></ul>

<p>However, in some instances, you may be required by LibreJS to add a
stylized comment to JavaScript code that may be otherwise trivial.
</p>
<p>When an external file defines a function, it becomes available
to all other external scripts. That is the case if another script
defines a function that makes AJAX calls, when an external script
loads other scripts dynamically (which in turn could also make AJAX
calls, &hellip;), or when a script is written with constructs that may do
any of these.
</p>
<p>For instance, if your page contains the following:
</p><div class="example">
<pre class="example">&lt;script src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
$.doSomething();
&lt;/script&gt;
</pre></div>

<p>While <code>$.doSomething();</code> may seem trivial, you will nevertheless
have to add a stylized license comment on your main HTML page because
the external script (in this case jQuery) has been found to define
methods that make AJAX calls. <code>$.doSomething()</code> might make an AJAX call,
and LibreJS does not check for that.  The rule of thumb is that when you
use a library or code that handles AJAX, JSON, JSONP, the loading of
scripts dynamically, you should have license mentions for all your
JavaScript files and for your main page regardless. In practice this is
a case that happens very often with code that uses libraries.
</p>
<p>In practice also, the JavaScript code in an external file (an external
<samp>.js</samp> file loaded on your page) may be found trivial if it does not
define functions/methods.
</p>
<p>And in the same manner it will be considered nontrivial if AJAX calls,
dynamic script loading, or non-obvious dynamic JavaScript constructs
are used in another script.
</p>
<p>If your JavaScript code makes AJAX requests, it&rsquo;s important to get an
accurate <em>Content-Type</em> in the response from the server. For
example, if you&rsquo;re using JSON, set it to <code>application/json</code>.
This is because LibreJS alters the content of <code>text/html</code>
responses.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Free-Licenses-Detection.html#Free-Licenses-Detection" accesskey="n" rel="next">Free Licenses Detection</a>, Previous: <a href="How-to-Use.html#How-to-Use" accesskey="p" rel="prev">How to Use</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
</div>



</body>
</html>