0
Hi,
I have a manifest.json that is working perfectly. The problem is I wanted his start_url to be dynamic and I could fill in.
I have seen answers from 2 years ago saying that it is not possible and some solutions that did not work ( I will put below ).
Can help me with a current message ?
{
"name": "Teste",
"short_name": "teste",
"theme_color": "#2196f3",
"background_color": "#2196f3",
"display": "standalone",
"Scope": "/m/",
"start_url": "",
"icons": [ {
"src": "../m/public/img/logo_192.png",
"sizes": "192x192",
"type": "image/png"
},{
"src": "../m/public/img/logo512.png",
"sizes": "512x512",
"type": "image/png"
}]
}
I tried to make a solution too that did not work, I created a php file and inserted .. It even works, but the pwa file is generated as link and not as installable app
What I’ve already tried
<script type="text/javascript">
var myDynamicManifest = {
"name": "Teste",
"short_name": "teste",
"theme_color": "#2196f3",
"background_color": "#2196f3",
"display": "standalone",
"Scope": "<?=DIRECTORY_ROOT?><?=$_SESSION['PagName']?>",
"start_url": "<?=DIRECTORY_ROOT?><?=$_SESSION['PagName']?>",
"icons": [ {
"src": "<?=PATH_IMAGE?>logo_192.png",
"sizes": "192x192",
"type": "image/png"
},{
"src": "<?=PATH_IMAGE?>logo512.png",
"sizes": "512x512",
"type": "image/png"
}]
};
const stringManifest = JSON.stringify(myDynamicManifest);
const blob = new Blob([stringManifest], {type: 'application/json'});
const manifestURL = URL.createObjectURL(blob);
document.querySelector('#manifesto').setAttribute('href', manifestURL);
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw_gdscartao.js').then(function(registration) {
console.log("Serviceworker Registrado");
}).catch(function(err) {
alert('erro' + err);
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
};
</script>
Hello friend, how did you make this deal? I’m in the same problem. Thank you
– Jonas Ferreira
Hi Jonas, all right ... give me your contact, I can explain in more detail.. but practically , I used a php file, with a call <? php <script type="text/javascript"> Equal ta in the second example of the initial post. ...
– Gabriel GMM