(f, sites, refreshes=0)
| 84 | |
| 85 | |
| 86 | def generate_injection(f, sites, refreshes=0): |
| 87 | print("""\ |
| 88 | (function() { |
| 89 | var s = window.sessionStorage.getItem("refreshCounter"); |
| 90 | var refreshTotal = """, refreshes, """; |
| 91 | var refreshCounter = s ? parseInt(s) : refreshTotal; |
| 92 | var refreshId = refreshTotal - refreshCounter; |
| 93 | if (refreshCounter > 0) { |
| 94 | window.sessionStorage.setItem("refreshCounter", refreshCounter-1); |
| 95 | } |
| 96 | function match(url, item) { |
| 97 | if ('regexp' in item) { return url.match(item.regexp) !== null }; |
| 98 | var url_wanted = item.url; |
| 99 | /* Allow automatic redirections from http to https. */ |
| 100 | if (url_wanted.startsWith("http://") && url.startsWith("https://")) { |
| 101 | url_wanted = "https://" + url_wanted.substr(7); |
| 102 | } |
| 103 | return url.startsWith(url_wanted); |
| 104 | }; |
| 105 | function onLoad(url) { |
| 106 | for (var item of sites) { |
| 107 | if (!match(url, item)) continue; |
| 108 | var timeout = 'timeline' in item ? 2000 * item.timeline |
| 109 | : 'timeout' in item ? 1000 * (item.timeout - 3) |
| 110 | : 10000; |
| 111 | console.log("Setting time out of " + timeout + " for: " + url); |
| 112 | window.setTimeout(function() { |
| 113 | console.log("Time is out for: " + url); |
| 114 | var msg = "STATS: (" + refreshId + ") " + url; |
| 115 | %GetAndResetRuntimeCallStats(1, msg); |
| 116 | if (refreshCounter > 0) { |
| 117 | console.log( |
| 118 | "Refresh counter is " + refreshCounter + ", refreshing: " + url); |
| 119 | window.location.reload(); |
| 120 | } |
| 121 | }, timeout); |
| 122 | return; |
| 123 | } |
| 124 | console.log("Ignoring: " + url); |
| 125 | }; |
| 126 | var sites = |
| 127 | """, json.dumps(sites), """; |
| 128 | onLoad(window.location.href); |
| 129 | })();""", file=f) |
| 130 | |
| 131 | def get_chrome_flags(js_flags, user_data_dir, arg_delimiter=""): |
| 132 | return [ |
no test coverage detected
searching dependent graphs…