Chrome | 109.0.0 | own | function | function handler(event) {
if (
event.source == window &&
event.data &&
event.data.direction == 'from-content-script'
) {
if (event.data.detach) {
window.removeEventListener('message', handler)
window.prompt = originalPrompt
window.confirm = originalConfirmation
window.alert = originalAlert
return
}
let result = undefined
switch (event.data.command) {
case 'setNextPromptResult':
nextPromptResult = event.data.target
document.body.setAttribute('setPrompt', true)
window.postMessage(
{
direction: 'from-page-script',
response: 'prompt',
},
'*'
)
break
case 'getPromptMessage':
result = recordedPrompt
recordedPrompt = null
window.postMessage(
{
direction: 'from-page-script',
response: 'prompt',
value: result,
},
'*'
)
break
case 'setNextConfirmationResult':
nextConfirmationResult = event.data.target
document.body.setAttribute('setConfirm', true)
window.postMessage(
{
direction: 'from-page-script',
response: 'confirm',
},
'*'
)
break
case 'getConfirmationMessage':
result = recordedConfirmation
recordedConfirmation = null
try {
window.postMessage(
{
direction: 'from-page-script',
response: 'confirm',
value: result,
},
'*'
)
} catch (e) {} // eslint-disable-line no-empty
break
case 'setNextAlertResult':
document.body.setAttribute('setAlert', true)
window.postMessage(
{
direction: 'from-page-script',
response: 'alert',
},
'*'
)
break
}
}
} |