mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-27 13:29:34 +07:00
* Remove docs folder. This was a redirect from a GitHub pages site that does not appear to be in use. * Rename api folder to api-samples. * Move examples to functional-samples folder. * Move cookbook sample to functional-samples. * Move tutorials to functional-samples folder. * Move mv2 and apps folders to _archive. * Rename tools folder to .repo. * Move reference folder to functional-samples. * Update README. Update README with new relative links for reorg. * Update README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> --------- Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
// Copyright (c) 2012 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.
|
|
|
|
var tabId = parseInt(window.location.search.substring(1));
|
|
|
|
window.addEventListener("load", function() {
|
|
chrome.debugger.sendCommand({tabId:tabId}, "Network.enable");
|
|
chrome.debugger.onEvent.addListener(onEvent);
|
|
});
|
|
|
|
window.addEventListener("unload", function() {
|
|
chrome.debugger.detach({tabId:tabId});
|
|
});
|
|
|
|
var requests = {};
|
|
|
|
function onEvent(debuggeeId, message, params) {
|
|
if (tabId != debuggeeId.tabId)
|
|
return;
|
|
|
|
if (message == "Network.requestWillBeSent") {
|
|
var requestDiv = requests[params.requestId];
|
|
if (!requestDiv) {
|
|
var requestDiv = document.createElement("div");
|
|
requestDiv.className = "request";
|
|
requests[params.requestId] = requestDiv;
|
|
var urlLine = document.createElement("div");
|
|
urlLine.textContent = params.request.url;
|
|
requestDiv.appendChild(urlLine);
|
|
}
|
|
|
|
if (params.redirectResponse)
|
|
appendResponse(params.requestId, params.redirectResponse);
|
|
|
|
var requestLine = document.createElement("div");
|
|
requestLine.textContent = "\n" + params.request.method + " " +
|
|
parseURL(params.request.url).path + " HTTP/1.1";
|
|
requestDiv.appendChild(requestLine);
|
|
document.getElementById("container").appendChild(requestDiv);
|
|
} else if (message == "Network.responseReceived") {
|
|
appendResponse(params.requestId, params.response);
|
|
}
|
|
}
|
|
|
|
function appendResponse(requestId, response) {
|
|
var requestDiv = requests[requestId];
|
|
requestDiv.appendChild(formatHeaders(response.requestHeaders));
|
|
|
|
var statusLine = document.createElement("div");
|
|
statusLine.textContent = "\nHTTP/1.1 " + response.status + " " +
|
|
response.statusText;
|
|
requestDiv.appendChild(statusLine);
|
|
requestDiv.appendChild(formatHeaders(response.headers));
|
|
}
|
|
|
|
function formatHeaders(headers) {
|
|
var text = "";
|
|
for (name in headers)
|
|
text += name + ": " + headers[name] + "\n";
|
|
var div = document.createElement("div");
|
|
div.textContent = text;
|
|
return div;
|
|
}
|
|
|
|
function parseURL(url) {
|
|
var result = {};
|
|
var match = url.match(
|
|
/^([^:]+):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
|
|
if (!match)
|
|
return result;
|
|
result.scheme = match[1].toLowerCase();
|
|
result.host = match[2];
|
|
result.port = match[3];
|
|
result.path = match[4] || "/";
|
|
result.fragment = match[5];
|
|
return result;
|
|
} |