I need to get a value from a variable but the content can’t be parsed automatically (json conversion fails and searches fail too).
Indeed, this content is usually displayed using standard browser and executed on windows load (this sends back the variable to be used later).
As Postman doesn’t generate this event, I don’t receive this variable and can’t extract it from the text.
In below an example, I need to extract data.access_token value :
<script type="text/javascript">
/**
* Check whether this page is loaded in an iframe or a popup.
*/
function isInIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
/**
* Create the message payload to send back to the parent window.
*/
function buildMessageData() {
var data = {};
data.access_token = '1024_random_characters';
data.token_type = 'Bearer';
data.expires_in = '900';
data.scope = 'openid\x20email\x20roles\x20tenant';
data.state = 'state';
return data;
}
/**
* On window load, post the message payload back to the parent window.
*/
function onWindowLoadHandler() {
var parentWindow = window.isInIframe() ? window.parent : window.opener;
parentWindow.postMessage(buildMessageData(), 'https\x3A\x2F\x2Fmyurl.com');
}
// Attach event handler for the 'DOM loaded' or equivalent event on the window
if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', onWindowLoadHandler, false);
} else if (window.attachEvent) {
// IE8
window.attachEvent('onload', onWindowLoadHandler);
}
</script>
</head>
<body>
Thanks in advance.