Skip to content

Commit

Permalink
traceviewer doesnt think it runs in a content script.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Oct 2, 2016
1 parent b60634d commit 562430c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lighthouse-core/scripts/build-traceviewer-module.js
Expand Up @@ -70,6 +70,8 @@ function convertImport(src) {

// node4 compat
scriptsContent = polyfillNode4Support(dest, scriptsContent);
// browser compat
scriptsContent = adjustForBrowserCompat(scriptsContent);

writeNewFile(dest, scriptsContent);

Expand Down Expand Up @@ -133,6 +135,12 @@ function convertImport(src) {
return transformed;
}

function adjustForBrowserCompat(scriptsContent) {
return scriptsContent
// early exit in tracing/base.ui and avoid currentScript from breaking us.
.replace('var THIS_DOC = document.currentScript.ownerDocument;', 'return;');
}

function writeNewFile(dest, scriptsContent) {
dest = dest.replace('./third_party/src/catapult/tracing/tracing/', '');
dest = path.resolve('./third_party/traceviewer-js/' + dest);
Expand Down
Expand Up @@ -24,7 +24,7 @@ require("./utils.js");
global.tr.exportTo('tr.ui.b', function () {
if (tr.isHeadless) return {};

var THIS_DOC = document.currentScript.ownerDocument;
return;

/**
* Creates a new overlay element. It will not be visible until shown.
Expand Down

0 comments on commit 562430c

Please sign in to comment.