Skip to content

Commit fb534b7

Browse files
committed
Fixed 'ReferenceError: document is not defined' when running under PhantomJS
1 parent 307e55a commit fb534b7

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tracekit",
33
"main": "tracekit.js",
4-
"version": "0.4.2",
4+
"version": "0.4.3",
55
"homepage": "https://github.com/csnover/TraceKit",
66
"description": "Cross browser stack traces",
77
"moduleType": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tracekit",
33
"main": "./tracekit.js",
4-
"version": "0.4.2",
4+
"version": "0.4.3",
55
"homepage": "https://github.com/csnover/TraceKit",
66
"description": "Cross browser stack traces",
77
"repository": {

tracekit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
421421
*/
422422
var source = '';
423423
var domain = '';
424-
try { domain = document.domain; } catch (e) { }
424+
try { domain = window.document.domain; } catch (e) { }
425425
var match = /(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(url);
426426
if (match && match[2] === domain) {
427427
source = loadSource(url);
@@ -592,12 +592,12 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
592592
* @memberof TraceKit.computeStackTrace
593593
*/
594594
function findSourceByFunctionBody(func) {
595-
if (_isUndefined(document)) {
595+
if (_isUndefined(window && window.document)) {
596596
return;
597597
}
598598

599599
var urls = [window.location.href],
600-
scripts = document.getElementsByTagName('script'),
600+
scripts = window.document.getElementsByTagName('script'),
601601
body,
602602
code = '' + func,
603603
codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
@@ -882,7 +882,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
882882
lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,
883883
lineRE3 = /^\s*Line (\d+) of function script\s*$/i,
884884
stack = [],
885-
scripts = document.getElementsByTagName('script'),
885+
scripts = (window && window.document && window.document.getElementsByTagName('script')),
886886
inlineScriptBlocks = [],
887887
parts;
888888

0 commit comments

Comments
 (0)