Commit e2effcbc authored by cbruni's avatar cbruni Committed by Commit bot

[tools] Support custom script injection for callstats.py

This is a poor-man's solution to trigger page interactions.

BUG=

Review-Url: https://codereview.chromium.org/2455623002
Cr-Commit-Position: refs/heads/master@{#40604}
parent 51bbfc7d
...@@ -84,6 +84,8 @@ def stop_replay_server(server): ...@@ -84,6 +84,8 @@ def stop_replay_server(server):
def generate_injection(f, sites, refreshes=0): def generate_injection(f, sites, refreshes=0):
print >> f, """\ print >> f, """\
(function() { (function() {
var sites =
""", json.dumps(sites), """;
var s = window.sessionStorage.getItem("refreshCounter"); var s = window.sessionStorage.getItem("refreshCounter");
var refreshTotal = """, refreshes, """; var refreshTotal = """, refreshes, """;
var refreshCounter = s ? parseInt(s) : refreshTotal; var refreshCounter = s ? parseInt(s) : refreshTotal;
...@@ -99,7 +101,15 @@ def generate_injection(f, sites, refreshes=0): ...@@ -99,7 +101,15 @@ def generate_injection(f, sites, refreshes=0):
url_wanted = "https://" + url_wanted.substr(7); url_wanted = "https://" + url_wanted.substr(7);
} }
return url.startsWith(url_wanted); return url.startsWith(url_wanted);
}; }
function runCustomScript(site) {
if (site.script === undefined) return;
/* Combine a script from the given array. */
if (typeof site.script !== "string") {
site.script = site.script.join(' ');
}
eval(site.script);
}
function onLoad(url) { function onLoad(url) {
for (var item of sites) { for (var item of sites) {
if (!match(url, item)) continue; if (!match(url, item)) continue;
...@@ -117,13 +127,15 @@ def generate_injection(f, sites, refreshes=0): ...@@ -117,13 +127,15 @@ def generate_injection(f, sites, refreshes=0):
window.location.reload(); window.location.reload();
} }
}, timeout); }, timeout);
runCustomScript(item);
return; return;
} }
console.log("Ignoring: " + url); console.log("Ignoring: " + url);
}; };
var sites = /* Avoid re-triggering the runtime stats for html imports */
""", json.dumps(sites), """; if (document.currentScript.ownerDocument === document) {
onLoad(window.location.href); onLoad(window.location.href);
}
})();""" })();"""
def get_chrome_flags(js_flags, user_data_dir): def get_chrome_flags(js_flags, user_data_dir):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment