Remove `self` from confusing-browser-globals
Created by: JoshuaCWebDeveloper
Is your proposal related to a problem?
Yes.
When writing code for a service worker, the global variable self
is used the same way window
is used in web pages; however, eslint will report errors when writing worker code since self
is banned via https://github.com/facebook/create-react-app/blob/main/packages/confusing-browser-globals/index.js.
Describe the solution you'd like
I believe we should remove self
from the confusing-browser-globals list.
Describe alternatives you've considered
The workbox CRA template simply places:
/* eslint-disable no-restricted-globals */
at the top of the service-worker.ts
file. This has the downside of removing all restricted global protections from your service worker code. Additionally, it is impractical for larger service worker codebases with many source files.
One can also use this
and globalThis
as an alternative to using self
. However, I still believe that self
should not be included in this list for the following reason:
-
self
in a worker is the equivalent ofwindow
in a web page -
window
is not included in the list, so neither shouldself