Environment
epos.env gives you information about where your code is running and which project it belongs to.
This is useful when the same code can run in different places or you need to access project information at runtime.
Basic Context Flags
The most common values are these three boolean flags:
epos.env.isPopupepos.env.isSidePanelepos.env.isBackground
Example:
if (epos.env.isBackground) {
console.log('Running in background')
}
if (epos.env.isPopup) {
console.log('Running in popup')
}These checks are often enough when you need slightly different startup logic in different contexts.
tabId and windowId
epos.env.tabId and epos.env.windowId tell you which browser tab and window the current code belongs to.
console.log(epos.env.tabId)
console.log(epos.env.windowId)You can use them with the epos.browser.tabs and epos.browser.windows APIs:
const tab = await epos.browser.tabs.get(epos.env.tabId)
const win = await epos.browser.windows.get(epos.env.windowId)For background code and iframes, these values are -1.
Project Information
epos.env.project contains information about the current project:
id- the internal project ID.spec- the normalizedepos.json.manifest- the generatedmanifest.jsonused for export.enabled- whether the project is enabled in the app.epos.dev dashboard.debug- whether the dev build of the engine is used,trueby default.pageUrl- the URL of the<page>target. Read more in the Action guide.
spec is useful when your code needs to read its own epos.json configuration. manifest is mostly useful for inspection and debugging.
debug can be changed in the app.epos.dev dashboard. It is always false for the exported bundle. Turn it off during development to test how your app behaves with the engine production build, including production builds of built-in libraries like React and MobX.
Example:
console.log(epos.env.project.id)
console.log(epos.env.project.spec.name)
if (!epos.env.project.debug) {
console.log('Using Epos production build')
}