Skip browser cache writes for non-http(s) resources#1723
Open
patrickkettner wants to merge 1 commit into
Open
Conversation
When a model is bundled inside a browser extension, cache.put() is called with a chrome-extension:// key on every file load. The browser Cache API only supports http(s) URLs as keys, so the put always fails: one call site warns on every load and the other has no error handling at all. Skip the write instead when the cache is the browser Cache API and the key is an absolute non-http(s) URL. Relative keys still get cached, since the Cache API resolves them against the page URL.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This replaces #614, the original report of this problem. That PR patched a file that has since been rewritten and moved, so it is being closed as obsolete in favor of this one. Related background: #380.
When a model is bundled inside a browser extension (
env.localModelPathpointing at achrome-extension://URL) with the browser cache enabled, every file load attemptscache.put()with achrome-extension://key. The browser Cache API only supports http(s) request keys, so the put always fails: one call site logsUnable to add response to browser cache: TypeError: ...on every load, and the streaming path has no error handling at all.This skips the write when the cache is the browser Cache API and the key is an absolute non-http(s) URL. Relative keys (e.g. the documented
env.localModelPath = '/path/to/models/'pattern) are unaffected, since the Cache API resolves those against the page URL, and the other cache backends (FileCache, custom caches, Cross-Origin Storage) are untouched. One remaining gap worth knowing about: an extension page using a relativelocalModelPathstill resolves to achrome-extension://request at put time; covering that would mean resolving keys against the page URL before the check, which seemed not worth the extra complexity here.Tests cover the extension case (no put attempted), the relative-path case (still cached), and the remote case (still cached).