[x] Nit: add JSDoc for promiseStore, trackLinks, and links, and add more explanation for each.
[x] Nit: use a more descriptive variable name for links.
[x] Nit: for consistency, rename resolveURL to resolveUrl and update references.
[x] Nit: drop the URL from the debugging output in the if(!initialized) check.
[x] Nit: use a more descriptive variable name than p.
[x] Nit: clarify the comment that reads "store this resolve object in promiseStore"
[x] Nit: don't call promiseStore.set if you're updating the array that's already in the promise store.
[ ] In resolveURL, try to resolve the URL as far as possible based on cached data before calling fetch.
[x] Add documentation explaining the User-Agent logic in resolveURL.
[x] Move the logic from getLocationFromResponseHeader into responseHeaderListener for concision.
[x] Nit: use a more descriptive variable name than loc.
[x] We should have a timeout for fetch requests generated by this library.
[ ] The webRequest listeners should fire for as few responses / errors as possible. At minimum, they should be configured for only known shortener domains and xmlhttprequest request types.
[ ] There should be a maximum recursion depth for resolving shortened links.
[ ] We need to carefully handle the scenario where multiple link resolutions converge to the same redirection path at the same time. You could imagine a race scenario where one resolution precludes another resolution. A possible solution would be to track not just the redirection path, but also the (possibly more than one) original URL for each step in the redirection path, to make sure that resolutions don't step on each other.
[x] Nit: add JSDoc for
promiseStore
,trackLinks
, andlinks
, and add more explanation for each.[x] Nit: use a more descriptive variable name for
links
.[x] Nit: for consistency, rename
resolveURL
toresolveUrl
and update references.[x] Nit: drop the URL from the debugging output in the
if(!initialized)
check.[x] Nit: use a more descriptive variable name than
p
.[x] Nit: clarify the comment that reads "store this resolve object in promiseStore"
[x] Nit: don't call
promiseStore.set
if you're updating the array that's already in the promise store.[ ] In
resolveURL
, try to resolve the URL as far as possible based on cached data before callingfetch
.[x] Add documentation explaining the
User-Agent
logic inresolveURL
.[x] Move the logic from
getLocationFromResponseHeader
intoresponseHeaderListener
for concision.[x] Nit: use a more descriptive variable name than
loc
.[x] We should have a timeout for
fetch
requests generated by this library.[ ] The
webRequest
listeners should fire for as few responses / errors as possible. At minimum, they should be configured for only known shortener domains andxmlhttprequest
request types.[ ] There should be a maximum recursion depth for resolving shortened links.
[ ] We need to carefully handle the scenario where multiple link resolutions converge to the same redirection path at the same time. You could imagine a race scenario where one resolution precludes another resolution. A possible solution would be to track not just the redirection path, but also the (possibly more than one) original URL for each step in the redirection path, to make sure that resolutions don't step on each other.