Search
Other Advanced Module Manager questions
Forum

PWA Condition

Massimiliano Zucchi's Avatar Massimiliano Zucchi
Good evening,
I wanted to know if it was possible, with your solution, to condition the display of some modules based on whether the site is visited in PWA mode rather than from the mobile browser.

With javascript it is possible to intercept the use of PWA example:
function isPWA() {
    // Check if the app is in "standalone" mode (installed as a PWA)
    return window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone;
}

I am not able to understand where I can (if possible) integrate it into the module management.
Can it be done? Or do you have alternative solutions?
Thank you.
Peter van Westen's Avatar Peter van Westen ADMIN
Check if the url has something unique in it when in pwa mode, like mode=standalone or _pwa=1
Then you can use that in the URL condition rule.
Please post a rating at the Joomla! Extensions Directory
Massimiliano Zucchi's Avatar Massimiliano Zucchi
hi Pietro,
When a PWA is running, the links and URLs are basically the same as the regular website. A PWA does not alter the URL or the way the site is structured. This means that the user will see the same URL whether they are using the PWA installed on the device or browsing via a browser.
Peter van Westen's Avatar Peter van Westen ADMIN
Then unless you set some cookies or something, no, that browser information is not available on server (php) side.
Please post a rating at the Joomla! Extensions Directory
Massimiliano Zucchi's Avatar Massimiliano Zucchi
Yes, in fact, this is the problem. I was thinking of using "Custom PHP" and doing something like this, do you think this would work?
in the index.php insert:
// PWA yes or no
const isStandalone = window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone;

if (isStandalone) {
    console.log("App is PWA standalone");
    fetch('your-server-script.php', {
        method: 'POST',
        body: JSON.stringify({ pwaMode: true }),
        headers: { 'Content-Type': 'application/json' }
    });
} else {
    console.log("App is normal");
    fetch('your-server-script.php', {
        method: 'POST',
        body: JSON.stringify({ pwaMode: false }),
        headers: { 'Content-Type': 'application/json' }
    });
}

and can I insert this code into the module manager in "Custom PHP"?
$data = json_decode(file_get_contents('php://input'), true);

if ($data && isset($data['pwaMode'])) {
    $isPWA = $data['pwaMode']; // True is PWA, False no PWA
}
could it work?
Peter van Westen's Avatar Peter van Westen ADMIN
You could try. Or set a cookie via javascript, and read it through php.

Issue is, that the javascript will be run AFTER the php has rendered the page. So on the first PWA page load, you'd have to reload the page.
Please post a rating at the Joomla! Extensions Directory
Massimiliano Zucchi's Avatar Massimiliano Zucchi
OK thank you. I will do some tests and if I have interesting and working developments I will share with you.
Thanks for your time.
Max
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription