I’m writing a chrome extension written in Kotlin and I ran into the following issues. In chrome there is a content script, a background script and a popup page. Now I load my Kotlin code into the background script and into the popup script. However, there seems to be two independent instances of my code that are completely separated, e.g. I can’t access any data from the background script in the popup.
To circumvent this problem I store my shared data in the background window object:
window.data = data
From the popup I can access this data using:
val backgroundWindow: dynamic = chrome.extension.getBackgroundPage() backgroundWindow.data
I have two issues.
- In my previous example, when I cast the data to the correct class it works fine:
val data: Data = backgroundWindow.data
However when I do:
process(backgroundWindow.data as Data)
the “as” throws an exception even though it is indeed of type Data. (Is that because there are two module instances and they both define the Data $metadata$ object?)