1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // This function is converted to a string and becomes the preprocessor
8 function preprocessor(source, url, listenerName) {
9 url = url ? url : '(eval)';
10 url += listenerName ? '_' + listenerName : '';
11 var prefix = 'window.__preprocessed = window.__preprocessed || [];\n';
12 prefix += 'window.__preprocessed.push(\'' + url +'\');\n';
13 var postfix = '\n//# sourceURL=' + url + '.js\n';
14 return prefix + source + postfix;
17 function extractPreprocessedFiles(onExtracted) {
18 var expr = 'window.__preprocessed';
19 function onEval(files, isException) {
21 throw new Error('Eval failed for ' + expr, isException.value);
24 chrome.devtools.inspectedWindow.eval(expr, onEval);
27 function reloadWithPreprocessor(injectedScript) {
31 injectedScript: '(' + injectedScript + ')()',
32 preprocessingScript: '(' + preprocessor + ')'
34 chrome.devtools.inspectedWindow.reload(options);
37 function demoPreprocessor() {
39 extractPreprocessedFiles(updateUI);
41 var loadMonitor = new InspectedWindow.LoadMonitor(onLoaded);
42 reloadWithPreprocessor(loadMonitor.injectedScript);
46 var reloadButton = document.querySelector('.reload-button');
47 reloadButton.addEventListener('click', demoPreprocessor);
50 window.addEventListener('load', listen);
52 function createRow(url) {
53 var li = document.createElement('li');
58 function updateUI(preprocessedFiles) {
59 var rowContainer = document.querySelector('.js-preprocessed-urls');
60 rowContainer.innerHTML = '';
61 preprocessedFiles.forEach(function(url) {
62 rowContainer.appendChild(createRow(url));