Skip to content

Commit

Permalink
Merge pull request #147 from /issues/138/1
Browse files Browse the repository at this point in the history
Fixes #138 - Send metadata via postMessage + change screenshot to be sent as blob
  • Loading branch information
Mike Taylor committed Nov 18, 2019
2 parents 40ef31d + 54278a2 commit b44dee1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions shared/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import isReportableURL from "./checkurl.js";

const PREFIX = "https://webcompat.com/issues/new?url=";
const PREFIX = "https://webcompat.com/issues/new";

function createContextMenu() {
chrome.contextMenus.create({
Expand All @@ -26,12 +26,28 @@ function reportIssue(tab, reporterID) {
chrome.tabs.captureVisibleTab({ format: "png" }, function(res) {
let screenshotData = res;
chrome.tabs.query({ currentWindow: true, active: true }, function(tab) {
var newTabUrl = `${PREFIX}${encodeURIComponent(
tab[0].url
)}&src=${reporterID}&utm_source=${reporterID}&utm_campaign=report-site-issue-extension`;
chrome.tabs.create({ url: newTabUrl }, function(tab) {
const json = JSON.stringify({
url: tab[0].url,
src: reporterID,
utm_source: reporterID,
utm_campaign: "report-site-issue-extension"
});

chrome.tabs.create({ url: PREFIX }, function(tab) {
chrome.tabs.executeScript(tab.id, {
code: `window.postMessage("${screenshotData}", "*")`
runAt: "document_end",
code: `
async function postMessageData(dataURI, metadata) {
const res = await fetch(dataURI);
const blob = await res.blob();
const data = {
screenshot: blob,
message: metadata
};
postMessage(data, "*");
}
postMessageData("${screenshotData}", ${json});
`
});
});
});
Expand Down

0 comments on commit b44dee1

Please sign in to comment.