Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "Load failed" message on Safari #280

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reduced logging and meta fixes
  • Loading branch information
fregante committed Mar 27, 2023
commit 595683048a4505e14a39e035b6c034eb4bb25dc8
6 changes: 2 additions & 4 deletions source/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async function handleAction({id}) {
...defaults,
code: 'typeof window.startGT === "function"',
});
console.log(alreadyInjected);
if (alreadyInjected) {
return browser.tabs.executeScript(id, {...defaults, code: 'startGT()'});
}
Expand All @@ -40,6 +39,7 @@ function handlePortListenerErrors(listener) {
await listener(port);
} catch (error) {
let {message} = error;
console.log({message});
fregante marked this conversation as resolved.
Show resolved Hide resolved
if ([
'Failed to fetch',
'NetworkError when attempting to fetch resource.',
Expand All @@ -64,11 +64,10 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => {

console.log('will open socket');
const socket = new WebSocket('ws://localhost:' + WebSocketPort);
const event = await Promise.race([
await Promise.race([
oneEvent(socket, 'open'),
oneEvent(socket, 'error'),
]);
console.log(event);

const onSocketClose = () => port.postMessage({close: true});
socket.addEventListener('close', onSocketClose);
Expand All @@ -79,7 +78,6 @@ chrome.runtime.onConnect.addListener(handlePortListenerErrors(async port => {
console.log('got message from script', message);
socket.send(message);
});
console.log(port);
port.onDisconnect.addListener(() => {
socket.removeEventListener('close', onSocketClose);
socket.close();
Expand Down
1 change: 1 addition & 0 deletions source/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ <h3>Info</h3>
<p>You can find information on how GhostText works and how to troubleshoot any issues on <a href="https://github.com/fregante/GhostText">its repo</a>.</p>
<p>If you find this useful, consider supporting its development by <a href="https://github.com/sponsors/fregante">donating or sponsoring me on GitHub</a>.</p>
<p>Made with 🍕 by <a href="https://fregante.com">fregante</a>.</p>
<!-- This breaks when using `npm run build`; Use `npm run prepare:safari` -->
<script type="module" src="options.js"></script>