Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Permission denied to access property "__v_isRef" on cross-origin object" #597

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/mixins/BaseSocial/BaseSocial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import {
PropType,
h,
DefineComponent,
markRaw,
} from 'vue';
import { IWindowFeatures } from '@/types/common/windowFeatures';
import getFormattedWindowFeatures from '@/utils/getFormattedWindowFeatures';
import getPopupClientRect from '@/utils/getPopupClientRect';
import { isUndefined } from '@/utils/inspect';

export interface IBaseSocialDataOptions {
shareDialog: Window | null;
shareDialogCloseIntervalId: number | undefined
dialog: {
shareDialog: Window | null;
shareDialogCloseIntervalId: number | undefined
}
}

export type TBaseSocialPropsOptions<T> = {
Expand Down Expand Up @@ -81,8 +84,10 @@ export default function BaseSocials<T>(

data(): IBaseSocialDataOptions {
return {
shareDialog: null,
shareDialogCloseIntervalId: undefined,
dialog: markRaw({
shareDialog: null,
shareDialogCloseIntervalId: undefined,
}),
};
},

Expand All @@ -92,7 +97,7 @@ export default function BaseSocials<T>(
* Make sure interval has been cleared
*/
beforeUnmount() {
window.clearInterval(this.shareDialogCloseIntervalId);
window.clearInterval(this.dialog.shareDialogCloseIntervalId);
},

computed: {
Expand Down Expand Up @@ -139,12 +144,12 @@ export default function BaseSocials<T>(
* If the pointer to the window object in memory does not exist
* or if such pointer exists but the window was closed
*/
if (this.shareDialog === null || this.shareDialog?.closed) {
if (this.dialog.shareDialog === null || this.dialog.shareDialog?.closed) {
/**
* then create it. The new window will be created and
* will be brought on top of any other window.
*/
this.shareDialog = window.open(
this.dialog.shareDialog = window.open(
url,
'_blank',
formattedFeatures,
Expand All @@ -153,7 +158,7 @@ export default function BaseSocials<T>(
* If window.open has been blocked – emit 'block' event and then do nothing
* If not – emit 'open' event
*/
if (!this.shareDialog) {
if (!this.dialog.shareDialog) {
this.$emit('popup-block');
return;
}
Expand All @@ -164,15 +169,15 @@ export default function BaseSocials<T>(
* So we check if it has been closed every 300 ms
* @link https://atashbahar.com/post/2010-04-27-detect-when-a-javascript-popup-window-gets-closed
*/
this.shareDialogCloseIntervalId = window.setInterval(() => {
if (this.shareDialog === null || this.shareDialog?.closed) {
window.clearInterval(this.shareDialogCloseIntervalId);
this.dialog.shareDialogCloseIntervalId = window.setInterval(() => {
if (this.dialog.shareDialog === null || this.dialog.shareDialog?.closed) {
window.clearInterval(this.dialog.shareDialogCloseIntervalId);
this.$emit('popup-close');
/**
* Unset reference to the popup window
* @link https://web.dev/detached-window-memory-leaks/#solution-unset-references
*/
this.shareDialog = null;
this.dialog.shareDialog = null;
}
}, 300);
} else {
Expand All @@ -182,7 +187,7 @@ export default function BaseSocials<T>(
* window with the focus() method. There would be no need to re-create
* the window or to reload the referenced resource.
*/
this.shareDialog.focus();
this.dialog.shareDialog.focus();
this.$emit('popup-focus');
}
},
Expand Down
Loading