-
Notifications
You must be signed in to change notification settings - Fork 0
Add feature to automatically close ERR_CACHE_MISS page #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
789d77c
Add feature to close tab when ERR_CACHE_MISS occurs
HashidaTKS ee3e32e
edge: Rename RepostConfirmationCancelerTalkClient to RepostConfirmati…
HashidaTKS 1e7bfd9
user-guide: add description about auto closing ERR_CACHE_MISS page
HashidaTKS 2c5d9de
Update test procedure
HashidaTKS fed0a81
doc: update PreReleaseTests.md
HashidaTKS fcc7696
test script: do not use multi char
HashidaTKS 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| [TARGETS] | ||
| *://localhost:8080* |
This file contains hidden or 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 hidden or 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,37 @@ | ||
| Add-Type -AssemblyName System.Net | ||
|
|
||
| $listener = New-Object System.Net.HttpListener | ||
| $listener.Prefixes.Add("http://localhost:8080/") | ||
| $listener.Start() | ||
| Write-Host "HTTP server running: http://localhost:8080/" | ||
|
|
||
| while ($listener.IsListening) { | ||
| try { | ||
| $context = $listener.GetContext() | ||
| $response = $context.Response | ||
| $request = $context.Request | ||
|
|
||
| # Disable cache in order to cause ERR_CACHE_MISS | ||
| $response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate") | ||
| $response.Headers.Add("Pragma", "no-cache") | ||
| $response.ContentType = "text/html" | ||
|
|
||
| $html = @" | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head><title>PowerShell HTTP Server</title></head> | ||
| <body> | ||
| <h1>No cached page</h1> | ||
| <p>This page is not cached</p> | ||
| </body> | ||
| </html> | ||
| "@ | ||
|
|
||
| $buffer = [System.Text.Encoding]::UTF8.GetBytes($html) | ||
| $response.ContentLength64 = $buffer.Length | ||
| $response.OutputStream.Write($buffer, 0, $buffer.Length) | ||
| $response.OutputStream.Close() | ||
| } catch { | ||
| Write-Warning "Error: $_" | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -47,13 +47,13 @@ function wildcardToRegexp(source) { | |
| * ] | ||
| * } | ||
| */ | ||
| const RepostConfirmationCancelerTalkClient = { | ||
| const RepostConfirmationCanceler = { | ||
| cached: null, | ||
|
|
||
| init() { | ||
| this.cached = null; | ||
| this.ensureLoadedAndConfigured(); | ||
| console.log('Running as RepostConfirmationCancelerTalkClient Talk client'); | ||
| console.log('Running RepostConfirmationCanceler'); | ||
| }, | ||
|
|
||
| async ensureLoadedAndConfigured() { | ||
|
|
@@ -114,7 +114,7 @@ const RepostConfirmationCancelerTalkClient = { | |
| return false; | ||
| }, | ||
|
|
||
| handleURL(config, url){ | ||
| handleURL(config, url, callbackWhenMatch){ | ||
| if (!url) { | ||
| console.log(`* Empty URL found`); | ||
| return false; | ||
|
|
@@ -135,7 +135,7 @@ const RepostConfirmationCancelerTalkClient = { | |
| console.log(`handleURL: check for section ${section.Name} (${JSON.stringify(section)})`); | ||
| if (this.match(section, urlToMatch)) { | ||
| console.log(` => unmatched`); | ||
| this.startMonitoring(); | ||
| callbackWhenMatch(); | ||
|
Contributor
Author
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. 今回の機能追加で、このメソッドを流用したい。ただ、今回追加した部分と従来の部分でマッチした場合にさせたい動作が異なる。
マッチ時にさせたい動作が異なるので、コールバック化して外部から渡せるようにした。 |
||
| return true; | ||
| } | ||
| else { | ||
|
|
@@ -153,7 +153,7 @@ const RepostConfirmationCancelerTalkClient = { | |
| for (const tab of tabs) { | ||
| const url = tab.url ?? tab.pendingUrl; | ||
| console.log(`handleAllTabs ${url} (tab=${tab.id})`); | ||
| if(this.handleURL(config, url)){ | ||
| if(this.handleURL(config, url, this.startMonitoring)){ | ||
| break; | ||
| } | ||
| }; | ||
|
|
@@ -169,15 +169,40 @@ const RepostConfirmationCancelerTalkClient = { | |
|
|
||
| const config = this.cached; | ||
| const url = tab.pendingUrl || tab.url; | ||
| this.handleURL(config, url); | ||
| this.handleURL(config, url, this.startMonitoring); | ||
| }, | ||
|
|
||
| onNavigationCommitted(details) { | ||
| const url = details.url; | ||
| console.log(`onNavigationCommitted: ${url}`); | ||
| const config = this.cached; | ||
| this.handleURL(config, url); | ||
| this.handleURL(config, url, this.startMonitoring); | ||
| }, | ||
|
|
||
| onErrorOccurred(details) { | ||
| console.log('onErrorOccurred:', details); | ||
| if (details.error === 'net::ERR_CACHE_MISS') { | ||
| const url = details.url; | ||
| const tabId = details.tabId; | ||
| const config = this.cached; | ||
| this.handleURL(config, url, () => { | ||
| this.closeTab(tabId); | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| closeTab(tabId) { | ||
| if (tabId !== -1) { | ||
| console.log("Closing tab:", tabId); | ||
| chrome.tabs.remove(tabId, () => { | ||
| if (chrome.runtime.lastError) { | ||
| console.log("Error while closing tab:", chrome.runtime.lastError.message) | ||
| } else { | ||
| console.log("Tab closed"); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| /* Refresh config for every N minute */ | ||
|
|
@@ -186,14 +211,19 @@ chrome.alarms.create('poll-config', {'periodInMinutes': ALARM_MINUTES}); | |
|
|
||
| chrome.alarms.onAlarm.addListener((alarm) => { | ||
| if (alarm.name === 'poll-config') { | ||
| RepostConfirmationCancelerTalkClient.configure(); | ||
| RepostConfirmationCancelerTalkClient.handleAllTabs(); | ||
| RepostConfirmationCanceler.configure(); | ||
| RepostConfirmationCanceler.handleAllTabs(); | ||
| //handleURL for all url in tabs. | ||
| } | ||
| }); | ||
|
|
||
| chrome.webRequest.onErrorOccurred.addListener( | ||
| RepostConfirmationCanceler.onErrorOccurred.bind(RepostConfirmationCanceler), | ||
| {urls: ["<all_urls>"]} | ||
| ); | ||
|
|
||
| /* Tab book-keeping for intelligent tab handlings */ | ||
| chrome.tabs.onUpdated.addListener(RepostConfirmationCancelerTalkClient.onTabUpdated.bind(RepostConfirmationCancelerTalkClient)); | ||
| chrome.webNavigation.onCommitted.addListener(RepostConfirmationCancelerTalkClient.onNavigationCommitted.bind(RepostConfirmationCancelerTalkClient)); | ||
| chrome.tabs.onUpdated.addListener(RepostConfirmationCanceler.onTabUpdated.bind(RepostConfirmationCanceler)); | ||
| chrome.webNavigation.onCommitted.addListener(RepostConfirmationCanceler.onNavigationCommitted.bind(RepostConfirmationCanceler)); | ||
|
|
||
| RepostConfirmationCancelerTalkClient.init(); | ||
| RepostConfirmationCanceler.init(); | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
このオブジェクトの中にERR_CACHE_MISSのページだったらタブを閉じる、という処理を追加した。
そのため単なるTalkClientではなくなったのでリネームした。