Chromium Code Reviews| Index: chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js |
| diff --git a/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..10eb8938e08d6d8ddc94e4728951487a2ae71cce |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/examples/api/devtools/inspectedWindow/chrome-preprocessor/Panel/InspectedWindowLoadMonitor.js |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +(function() { |
| + /* |
| + * @param {function} Called after the 'load' event on the inspected window |
| + * @ return {function} A function to be injected into the inspected window. |
|
Mike West
2013/09/04 08:54:37
Nit: space after @.
johnjbarton
2013/09/04 18:57:48
Done.
|
| + */ |
| + |
|
Mike West
2013/09/04 08:54:37
Nit: kill the newline.
johnjbarton
2013/09/04 18:57:48
Done.
|
| + function LoadMonitor(onLoadedCallback) { |
| + |
| + function checkForLoad() { |
| + var expr = 'window.__inspectedWindowLoaded'; |
| + function onEval(isLoaded, isException) { |
| + if (isException) |
| + throw new Error('Eval failed for ' + expr, isException.value); |
| + if (isLoaded) |
| + onLoadedCallback(); |
| + else |
| + pollForLoad(); |
| + } |
| + chrome.devtools.inspectedWindow.eval(expr, onEval); |
| + } |
| + |
| + function pollForLoad() { |
| + setTimeout(checkForLoad, 200); |
|
Mike West
2013/09/04 08:54:37
Hrm. Is there no event you could hook into? The po
Addy Osmani
2013/09/04 12:28:02
Afaik there isn't an alternative hook that could b
johnjbarton
2013/09/04 18:57:48
I added a fileoverview comment. See also https://c
|
| + } |
| + |
| + pollForLoad(); |
| + } |
| + |
| + LoadMonitor.prototype = { |
| + // This function should be converted to a string and run in the Web page |
| + injectedScript: function() { |
| + // Initialize a secret data structure. |
| + window.__inspectedWindowLoaded = false; |
| + window.addEventListener('load', function() { |
| + window.__inspectedWindowLoaded = true; |
| + }); |
| + } |
| + }; |
| + |
| + window.InspectedWindow = window.InspectedWindow || {}; |
| + InspectedWindow.LoadMonitor = LoadMonitor; |
| +})(); |
| + |
| + |