MOBILE-3401 iframe: Don't call cookies plugin if no domain

main
Dani Palou 2020-06-22 09:04:33 +02:00
parent a1b557d926
commit 68b963638a
1 changed files with 8 additions and 6 deletions

View File

@ -106,17 +106,19 @@ export class CoreIframeComponent implements OnChanges {
if (changes.src) { if (changes.src) {
const url = this.urlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue; const url = this.urlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue;
if (this.platform.is('ios') && !this.urlUtils.isLocalFileUrl(url)) { if (this.platform.is('ios') && url && !this.urlUtils.isLocalFileUrl(url)) {
// Save a "fake" cookie for the iframe's domain to fix a bug in WKWebView. // Save a "fake" cookie for the iframe's domain to fix a bug in WKWebView.
try { try {
const win = <WKWebViewCookiesWindow> window; const win = <WKWebViewCookiesWindow> window;
const urlParts = CoreUrl.parse(url); const urlParts = CoreUrl.parse(url);
await win.WKWebViewCookies.setCookie({ if (urlParts.domain) {
name: 'MoodleAppCookieForWKWebView', await win.WKWebViewCookies.setCookie({
value: '1', name: 'MoodleAppCookieForWKWebView',
domain: urlParts.domain, value: '1',
}); domain: urlParts.domain,
});
}
} catch (err) { } catch (err) {
// Ignore errors. // Ignore errors.
this.logger.error('Error setting cookie', err); this.logger.error('Error setting cookie', err);