-
Notifications
You must be signed in to change notification settings - Fork 75
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
Extension: Fix multiple inits (onload) #307
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -36,6 +36,12 @@ type IconStyle = { | |
text: string, | ||
} | ||
|
||
// https://developer.chrome.com/docs/extensions/reference/webNavigation/#type-onCompleted-callback-details | ||
type WebNavigationInfo = { | ||
frameId: number, | ||
tabId: number, | ||
url: string, | ||
}; | ||
|
||
// TODO this can be tested? | ||
function getIconStyle(result: Result): IconStyle { | ||
|
@@ -99,9 +105,9 @@ function getIconStyle(result: Result): IconStyle { | |
} | ||
|
||
|
||
async function updateState (tab: chrome$Tab) { | ||
async function onTabLoaded(tab: WebNavigationInfo) { | ||
const url = unwrap(tab.url); | ||
const tabId = unwrap(tab.id); | ||
const tabId = unwrap(tab.tabId); | ||
|
||
if (ignored(url)) { | ||
// todo reflect in the sidebar/popup? | ||
|
@@ -214,7 +220,7 @@ async function updateState (tab: chrome$Tab) { | |
visits = new Visits(url, url, [visits]) | ||
} | ||
console.assert(visits instanceof Visits) | ||
|
||
// right, we can't inject code into error pages (effectively, internal). For these, display popup instead of sidebar? | ||
// TODO and show system wide notification instead of tab notification? | ||
// https://stackoverflow.com/questions/32761782/can-a-chrome-extension-run-code-on-a-chrome-error-page-i-e-err-internet-disco | ||
|
@@ -454,40 +460,25 @@ chrome.webNavigation.onDOMContentLoaded.addListener(detail => { | |
// chrome.tabs.onReplaced.addListener(updateState); | ||
|
||
// $FlowFixMe | ||
chrome.tabs.onUpdated.addListener(defensify(async (tabId: number, info, tab: chrome$Tab) => { | ||
// too spammy in logs | ||
delete tab.favIconUrl | ||
delete info.favIconUrl | ||
// | ||
console.debug('onUpdated %o %o', tab, info) | ||
webNavigation = chrome.webNavigation; | ||
webNavigation.onCompleted.addListener(defensify(async (info: WebNavigationInfo) => { | ||
console.debug('onCompleted %o %o', info) | ||
|
||
const url = tab.url | ||
const url = info.url | ||
const ireason = ignored(url) | ||
if (ireason != null) { | ||
/* on Vivaldi I've seen url being "" */ | ||
console.debug('onUpdated %s: ignoring, reason: %s', url, ireason) | ||
console.debug('onCompleted %s: ignoring, reason: %s', url, ireason) | ||
} | ||
// right, tab updated triggered quite a lot, e.g. when the title is blinking | ||
// ok, so far there are basically two cases | ||
// 1. you open new tab. in that case 'url' won't be passed but onDomContentLoaded will be triggered | ||
// 2. you navigate within the same tab, e.g. on youtube. then url will be passed, but onDomContentLoaded doesn't trigger. TODO not sure if it's always the case. maybe it's only YT | ||
// TODO shit, so we might need to hide previous dots? ugh... | ||
|
||
// TODO vvvv these might need to be cleaned up; not sure how relevant... | ||
// page refresh: loading -> complete (no url at any point) | ||
// clicking on link: loading (url) -> complete | ||
// opening new link: loading -> loading (url) -> complete | ||
// ugh. looks like 'complete' is the most realiable??? | ||
// but, I checked with 'complete' and sometimes it would reload many things with loading -> complete..... shit. | ||
|
||
// also if you, say, go to web.telegram.org it's gonna show multiple notifications due to redirect... but perhaps this can just be suppressed.. | ||
if (info.frameId !== 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this check go first (before the URL check)? would make it faster and less logging |
||
return | ||
} | ||
|
||
if (info['status'] != 'complete') { | ||
return | ||
} | ||
console.info('requesting! %s', url) | ||
|
||
try { | ||
await updateState(tab); | ||
await onTabLoaded(info); | ||
} catch (error) { | ||
const message = error.message; | ||
if (message == null) { | ||
|
@@ -505,8 +496,7 @@ chrome.tabs.onUpdated.addListener(defensify(async (tabId: number, info, tab: chr | |
} | ||
throw error; | ||
} | ||
}, 'onUpdated')); | ||
|
||
}, 'onCompleted')); | ||
|
||
export async function getActiveTab(): Promise<?chrome$Tab> { | ||
const tabs = await achrome.tabs.query({ | ||
|
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
"tabs", | ||
"activeTab", | ||
"webNavigation", | ||
|
||
"notifications" | ||
], | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, looks like this is causing these for me