- Issue created by @Grevil
Inside the PWAController's "serviceWorkerRegistration()" method, the serviceworker.js gets populated with drupal data. Some of the logic on how the js gets populated is a bit flawed. Especially line 275, where data gets injected based on comments in code:
$replace = [
'[/*cacheUrls*/]' => Json::encode($cacheWhitelist),
'[/*activeLanguages*/]' => Json::encode(array_keys($languages)),
'[/*exclude_cache_url*/]' => Json::encode($exclude_cache_url),
"'/offline'/*offlinePage*/" => "'" . $config->get('offline_page') . "'",
'[/*modulePath*/]' => '/' . $this->moduleHandler->getModule('pwa')->getPath(),
'1/*cacheVersion*/' => '\'' . $this->getCacheVersion() . '\'',
'false/*pwaSkipWaiting*/' => $skip_waiting,
];
And one example from the javascript, where the data gets injected:
// Active languages on the site.
const ACTIVE_LANGUAGES = [/*activeLanguages*/];
This feels off. Shouldn't this be possible through simply adding these variables through the drupal settings js API? Couldn't we simply inject this data through the "pwa_page_attachments()" method, similiar to how the "scope" is passed to the "serviceworker-load.js"? Or is this NOT possible because of basically copying the "serviceworker.js" or other general serviceworker cache flaws?
Active
2.0
Code