I am working on an Angular based PWA. The app has social media share buttons generated using the ngx-share/core Module. These buttons work perfectly except on the PWA version of the site running on iOS. When the user clicks on the share button, the OS automatically opens the relevant installed app (ie. twitter) to allow the sharing, all meta data comes through, however when you return to the PWA, it now shows a blank white screen, even if you close and re-open the PWA. What I believe is happening, and through some debugging I found upon clicking the share button iOS seems to automatically navigate the PWA to a new about:blank page, and then hard caches this url, resulting in a blank white screen.
I have tried multiple fixes but nothing seems to work. I have tried adding event.preventDefault() to the click event, and even a history.go(-1), but this doesn't seem to have any effect as it automatically navigates away from this page, so no code is actually executed. I have tried editing the manifest.json , both the scope and start_url. I have tried editing the cache values in the ngsw-config.json. Since the Module seems to handle the links to the social media, I can not add target="_blank", and not sure this would solve the problem, as it seems to be a iOS specific issue.
article.component.html
<div class="share-container">
<share-buttons
[theme]="'modern-dark'"
[include]="['facebook', 'twitter', 'linkedin']"
[show]="3"
[showText]="true"
[showCount]="true"
[autoSetMeta]="true"
[title]="postTitle"
[description]="postDescription"
[image]="postImage"
(click)="incrementCounter($event)"
[url]="shareUrl"
></share-buttons>
</div>
article.component.ts
incrementCounter(event) {
event.preventDefault();
let social = event.target.innerHTML.toLowerCase().trim();
var url = this.config.url + '/wp-endpoint/' + social;
const httpFormOptions = {
headers: new HttpHeaders({}),
};
const httpFormData = new FormData();
httpFormData.append('post_id', this.post_id);
this.httpClient.post<any>(url, httpFormData, httpFormOptions).subscribe(data => {
switch (data.platform) {
case 'facebook_share_count':
$('#Facebook').html(data.count);
break;
case 'twitter_share_count':
$('#Twitter').html(data.count);
break;
case 'linkedin_share_count':
$('#LinkedIn').html(data.count);
break;
}
});
}
manifest.json
"theme_color": "#93d50a",
"background_color": "#fafafa",
"display": "standalone",
"scope": "/content-hub/",
"start_url": "/content-hub/",
"icons": []
ngsw-config.json
"dataGroups" : [
{
"name" : "api-fresh",
"urls" : [
"/category/*"
],
"cacheConfig" : {
"maxSize": 100,
"maxAge": "1h",
"timeout": "10s",
"strategy": "freshness"
}
}, {
"name": "api-performance",
"urls": [
"/"
],
"cacheConfig": {
"maxSize": 100,
"maxAge": "1d",
"strategy": "performance"
}
}
]