-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(panel): Add the "Report a broken page" view
- Loading branch information
Showing
25 changed files
with
389 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Ghostery Browser Extension | ||
* https://www.ghostery.com/ | ||
* | ||
* Copyright 2017-present Ghostery GmbH. All rights reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0 | ||
*/ | ||
|
||
import getBrowserInfo from '/utils/browser-info.js'; | ||
import { SUPPORT_PAGE_URL } from '/utils/urls.js'; | ||
|
||
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { | ||
if (msg.action === 'report-broken-page') { | ||
(async () => { | ||
try { | ||
const formData = new FormData(); | ||
const browserInfo = await getBrowserInfo(); | ||
|
||
formData.append('support_ticket[user_name]', ''); | ||
formData.append('support_ticket[user_email]', msg.email); | ||
formData.append( | ||
'support_ticket[subject]', | ||
`[GBE] Broken page report: ${msg.url}`, | ||
); | ||
formData.append('support_ticket[message]', msg.description); | ||
formData.append('support_ticket[selected_browser]', browserInfo.name); | ||
formData.append('support_ticket[browser_version]', browserInfo.version); | ||
formData.append('support_ticket[selected_os]', browserInfo.osVersion); | ||
formData.append('support_ticket[os_version]', ''); | ||
|
||
if (msg.screenshot) { | ||
const screenshot = await chrome.tabs.captureVisibleTab(null, { | ||
format: 'jpeg', | ||
quality: 100, | ||
}); | ||
formData.append( | ||
'support_ticket[screenshot]', | ||
await fetch(screenshot).then((res) => res.blob()), | ||
'screenshot.jpeg', | ||
); | ||
} | ||
|
||
await fetch(SUPPORT_PAGE_URL, { | ||
method: 'POST', | ||
body: formData, | ||
}).then((res) => { | ||
if (!res.ok || res.status > 204) { | ||
throw new Error( | ||
`Sending report has failed with status: ${res.status}`, | ||
); | ||
} | ||
}); | ||
|
||
sendResponse(); | ||
} catch (e) { | ||
sendResponse(e.message); | ||
} | ||
})(); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"storage", | ||
"scripting", | ||
"tabs", | ||
"activeTab", | ||
"webRequest", | ||
"offscreen" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"storage", | ||
"scripting", | ||
"tabs", | ||
"activeTab", | ||
"webNavigation", | ||
"webRequest", | ||
"webRequestBlocking", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Ghostery Browser Extension | ||
* https://www.ghostery.com/ | ||
* | ||
* Copyright 2017-present Ghostery GmbH. All rights reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0 | ||
*/ | ||
|
||
import { html, router } from 'hybrids'; | ||
|
||
import contributionImage from '../assets/contribution.svg'; | ||
|
||
export default { | ||
render: () => html` | ||
<template layout="column grow"> | ||
<ui-header> | ||
<div layout="row gap items:center"> | ||
<ui-icon name="report" layout="size:2"></ui-icon> | ||
Report a broken page | ||
</div> | ||
<ui-action slot="actions"> | ||
<a href="${router.backUrl()}"> | ||
<ui-icon name="close" color="gray-800" layout="size:3"></ui-icon> | ||
</a> | ||
</ui-action> | ||
</ui-header> | ||
<panel-container> | ||
<div layout="column items:center gap padding:2:2:4"> | ||
<img | ||
src="${contributionImage}" | ||
alt="Contribution" | ||
layout="size:20 margin:3" | ||
/> | ||
<ui-text type="headline-s" layout="block:center width:::40"> | ||
Thank you for your report! | ||
</ui-text> | ||
<ui-text type="body-m" layout="block:center width:::36"> | ||
We appreciate your help in making the web a better place. | ||
</ui-text> | ||
</div> | ||
</panel-container> | ||
</template> | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* Ghostery Browser Extension | ||
* https://www.ghostery.com/ | ||
* | ||
* Copyright 2017-present Ghostery GmbH. All rights reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0 | ||
*/ | ||
|
||
import { html, router, store } from 'hybrids'; | ||
|
||
import Session from '/store/session.js'; | ||
import { getCurrentTab } from '/utils/tabs.js'; | ||
|
||
import ReportConfirm from './report-confirm.js'; | ||
|
||
const Form = { | ||
url: '', | ||
email: '', | ||
description: '', | ||
screenshot: false, | ||
[store.connect]: { | ||
async get() { | ||
const [currentTab, session] = await Promise.all([ | ||
getCurrentTab(), | ||
store.resolve(Session), | ||
]); | ||
|
||
const url = currentTab && new URL(currentTab.url); | ||
|
||
return { | ||
url: url ? `${url.origin}${url.pathname}` : '', | ||
email: session.email, | ||
}; | ||
}, | ||
async set(_, values) { | ||
const error = await chrome.runtime.sendMessage({ | ||
action: 'report-broken-page', | ||
...values, | ||
}); | ||
|
||
if (error) throw new Error(error); | ||
|
||
return values; | ||
}, | ||
}, | ||
}; | ||
|
||
function submit(host, event) { | ||
try { | ||
router.resolve( | ||
event, | ||
store.submit(host.form).then(() => store.clear(Form)), | ||
); | ||
} catch { | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
export default { | ||
form: store(Form, { draft: true }), | ||
render: ({ form }) => html` | ||
<template layout="column grow shrink"> | ||
<ui-header> | ||
<div layout="row gap items:center"> | ||
<ui-icon name="report" layout="size:2"></ui-icon> | ||
Report a broken page | ||
</div> | ||
<ui-action slot="actions"> | ||
<a href="${router.backUrl()}"> | ||
<ui-icon name="close" color="gray-800" layout="size:3"></ui-icon> | ||
</a> | ||
</ui-action> | ||
</ui-header> | ||
<panel-container> | ||
${store.ready(form) && | ||
html` | ||
<form | ||
layout="column gap:2 padding:2" | ||
onsubmit="${submit}" | ||
action="${router.url(ReportConfirm)}" | ||
> | ||
${store.error(form) && | ||
!store.pending(form) && | ||
html` | ||
<div layout="row gap items:center"> | ||
<ui-icon | ||
name="warning" | ||
layout="inline size:2" | ||
color="danger-700" | ||
></ui-icon> | ||
<ui-text color="danger-700"> | ||
${store.error(form).message} | ||
</ui-text> | ||
</div> | ||
`} | ||
<ui-text layout="width:::40"> | ||
Inform us about a broken page so we can investigate and fix it. | ||
</ui-text> | ||
<ui-line></ui-line> | ||
<ui-text | ||
type="label-s" | ||
color="primary-700" | ||
style="word-break: break-all" | ||
layout="width:::40" | ||
> | ||
${form.url} | ||
</ui-text> | ||
<ui-input> | ||
<textarea | ||
placeholder="Describe the issue" | ||
rows="4" | ||
autocomplete="off" | ||
style="resize: vertical" | ||
oninput="${html.set(form, 'description')}" | ||
maxlength="5000" | ||
layout="::ui:font:body-s" | ||
required | ||
></textarea> | ||
</ui-input> | ||
<ui-input> | ||
<input | ||
type="email" | ||
name="email" | ||
placeholder="Email address" | ||
layout="::ui:font:body-s" | ||
value="${form.email}" | ||
oninput="${html.set(form, 'email')}" | ||
required | ||
/> | ||
</ui-input> | ||
<label layout="row gap items:center"> | ||
<input | ||
type="checkbox" | ||
onchange="${html.set(form, 'screenshot')}" | ||
/> | ||
<ui-text type="body-s"> | ||
Include a screenshot of this page | ||
</ui-text> | ||
</label> | ||
<ui-line></ui-line> | ||
<div layout="grid:2 gap:1"> | ||
<ui-button type="transparent" disabled="${store.pending(form)}"> | ||
<a href="${router.backUrl()}">Cancel</a> | ||
</ui-button> | ||
<ui-button type="primary" disabled="${store.pending(form)}"> | ||
<button type="submit">Send</button> | ||
</ui-button> | ||
</div> | ||
</form> | ||
`} | ||
</panel-container> | ||
</template> | ||
`, | ||
}; |
Oops, something went wrong.