Skip to content

Commit e2effcb

Browse files
camillobruniCommit bot
authored andcommitted
[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}
1 parent 51bbfc7 commit e2effcb

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tools/callstats.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def stop_replay_server(server):
8484
def generate_injection(f, sites, refreshes=0):
8585
print >> f, """\
8686
(function() {
87+
var sites =
88+
""", json.dumps(sites), """;
8789
var s = window.sessionStorage.getItem("refreshCounter");
8890
var refreshTotal = """, refreshes, """;
8991
var refreshCounter = s ? parseInt(s) : refreshTotal;
@@ -99,7 +101,15 @@ def generate_injection(f, sites, refreshes=0):
99101
url_wanted = "https://" + url_wanted.substr(7);
100102
}
101103
return url.startsWith(url_wanted);
102-
};
104+
}
105+
function runCustomScript(site) {
106+
if (site.script === undefined) return;
107+
/* Combine a script from the given array. */
108+
if (typeof site.script !== "string") {
109+
site.script = site.script.join(' ');
110+
}
111+
eval(site.script);
112+
}
103113
function onLoad(url) {
104114
for (var item of sites) {
105115
if (!match(url, item)) continue;
@@ -117,13 +127,15 @@ def generate_injection(f, sites, refreshes=0):
117127
window.location.reload();
118128
}
119129
}, timeout);
130+
runCustomScript(item);
120131
return;
121132
}
122133
console.log("Ignoring: " + url);
123134
};
124-
var sites =
125-
""", json.dumps(sites), """;
126-
onLoad(window.location.href);
135+
/* Avoid re-triggering the runtime stats for html imports */
136+
if (document.currentScript.ownerDocument === document) {
137+
onLoad(window.location.href);
138+
}
127139
})();"""
128140

129141
def get_chrome_flags(js_flags, user_data_dir):

0 commit comments

Comments
 (0)