Message loops checks coping with multiple options window.

This commit is contained in:
hackademix 2018-09-09 14:57:09 +02:00
parent c5cbb8abfc
commit 002c8f8b67
1 changed files with 5 additions and 3 deletions

View File

@ -24,10 +24,12 @@
answers.length === 1 ? answers.pop(): Promise.all(answers)
);
}
let context = typeof window === "object" && window.location.href || null;
let context = typeof window === "object" && window.location.href || "?";
let originalSender = __meta.originalSender || sender;
if (context === originalSender.url || context === sender.url) {
throw new Error("Message %s (%o) looping to its sender (%s)", name, msg, context);
let {url} = originalSender;
if (url && context.replace(/[?#].*/, '') === url.replace(/[?#].*/, '')) {
throw new Error(`Message ${name} ${JSON.stringify(msg)} looping to its sender (${context})`);
}
console.debug("Warning: no handler for message %o in context %s", msg, context);
if (originalSender.tab && originalSender.tab.id) {