question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ZoneAwarePromise conflicts with native CacheStorage

See original GitHub issue

I’m working on a project where I wanted to dynamically cache URLs in browsers native CacheStorage, that is also accessed by the service worker.

I just try to access the cache like this:

window.caches.open(CACHE_NAME)
  .then(cache => cache.addAll(ARRAY_OF_URLS))
  .catch(err => console.log('error while caching', err));

I get the error:

ERROR Error: Uncaught (in promise): TypeError: the given value is not a Promise

I can easily reproduce this by typing window.caches.open('testcache').then(result => result.add('/')) on the browser console window my angular app.

I assume this problem is caused because the native Promise is overwritten by ZoneAwarePromise but I’m not able to really find the root cause.

I’m running on Angular 5.2.11 and zone.js 0.8.26. Browser is Chrome, version 69.0.3497.35 beta (64-bit) on a Chromebook.

I found a workaround for my problem that I documented on stackoverflow on a matching problem. https://stackoverflow.com/a/52083423/2258093

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Sep 2, 2018

@davemecha, I don’t know the cause either, maybe the native implementation of cache.add will check the promise is native or not.

so another walkaround is just using cache.put.

fetch(url).then(function(response) {
  if (!response.ok) {
    throw new TypeError('bad response status');
  }
  return cache.put(url, response);
})
0reactions
angular-automatic-lock-bot[bot]commented, Nov 23, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 5 with CacheStorage - Stack Overflow
Unfortunately the CacheStorage somehow expects a native Promise instead of Angular's ZoneAwarePromise and throws an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found