Skip to content

Commit

Permalink
chore(#261): functionality working
Browse files Browse the repository at this point in the history
  • Loading branch information
micmro committed Oct 6, 2019
1 parent aed850a commit 60df175
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/ts/transformers/har-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ function makeContentTab(entry: Entry) {
function makeRawData(entry: Entry) {
return makeLazyWaterfallEntryTab(
"Raw Data",
() => `<pre><code>${escapeHtml(JSON.stringify(entry, null, 2))}</code></pre>`,
() => {
// class `copy` needed to catch bubbled up click event in `details-overlay/html-details-body.ts`
return `
<button class="copy-raw-data">Copy Raw Data to Clipboard</button>
<pre><code>${escapeHtml(JSON.stringify(entry, null, 2))}</code></pre>
`;
},
"raw-data rendered-data",
);
}
Expand Down
23 changes: 21 additions & 2 deletions src/ts/waterfall/details-overlay/svg-details-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ function createHolder(y: number, detailsHeight: number) {
return holder;
}

/** Shared function to copy raw data */
const onRawDataCopyClick = (event: MouseEvent) => {
const btn = event.target as HTMLButtonElement;
if (btn.tagName.toLowerCase() === "button" && btn.classList.contains("copy-raw-data")) {
const data = btn.nextElementSibling ? (btn.nextElementSibling as HTMLElement).innerText : "";
const el = document.createElement("textarea");
el.value = data;
document.body.appendChild(el);
el.select();
el.setSelectionRange(0, 99999);
document.execCommand("copy");
document.body.removeChild(el);
}
};

export function createRowInfoOverlay(overlay: OpenOverlay, y: number, detailsHeight: number): SVGGElement {
const requestID = overlay.index + 1;
const holder = createHolder(y, detailsHeight);
Expand All @@ -51,10 +66,14 @@ export function createRowInfoOverlay(overlay: OpenOverlay, y: number, detailsHei
y,
});

const body = createDetailsBody(requestID, detailsHeight, overlay.entry);
const closeBtn = createCloseButtonSvg(y);
closeBtn.addEventListener("click", () => overlay.onClose(overlay.index));
closeBtn.addEventListener("click", () => {
overlay.onClose(overlay.index);
body.removeEventListener("click", onRawDataCopyClick);
});
body.addEventListener("click", onRawDataCopyClick);

const body = createDetailsBody(requestID, detailsHeight, overlay.entry);
// need to re-fetch the elements to fix Edge "Invalid Calling Object" bug
const getButtons = () => body.getElementsByClassName("tab-button") as NodeListOf<HTMLButtonElement>;
const getTabs = () => body.getElementsByClassName("tab") as NodeListOf<HTMLDivElement>;
Expand Down

0 comments on commit 60df175

Please sign in to comment.