Visualize Html Not Working

My response html like this

<!doctype html>
<html lang="en">
<head>
    <title>test Mock 3D-Secure Processing Page</title>
</head>
<body>
<form id="test-3ds-form" action="*******************************************************" method="post">
    <input type="hidden" name="orderId" value="*******************************************************" />
    <input type="hidden" name="bin" value="123123123" />
    <input type="hidden" name="successUrl" value="*******************************************************" />
    <input type="hidden" name="failureUrl" value="*******************************************************" />
    <input type="hidden" name="confirmationUrl" value="*******************************************************" />
    <input type="hidden" name="PaReq" value="*******************************************************" />
</form>
<script type="text/javascript">
    document.getElementById("test-3ds-form").submit();
</script>
</body>
</html>

and my tests script like this


const htmlContent = pm.response.json().htmlContent;

function fixHTML(html) {



const fixedHTML = html.replace(/<input(.*?)>/g, '<input$1 />');



const cleanedHTML = fixedHTML.replace(/onclick=".*?"/g, '');



return cleanedHTML;

}



const fixedHTMLContent = fixHTML(htmlContent);

// Set the visualizer template and payload

pm.visualizer.set(fixedHTMLContent);

Tests script working but not visualizing anything. How can i fix it ?

Hey @baha-bayar

Welcome to the Postman Community! :postman:

I’m not sure I follow what you have in place here, is the response from your API HTML or JSON?

I’m confused by this line:

const htmlContent = pm.response.json().htmlContent;

I’d recommend taking a look through the learning center, to get more of an idea about how you can visualize your responses:

This link also contains example references that you can take a look through.

It’s my api response and my body like this
{
“htmlContent”: “My Html Content Is Here”
“status”: “success”,
“errorCode”: null,
“errorMessage”: null,
“errorGroup”: null,
“locale”: “tr”,
“systemTime”: 1697216390962,
“conversationId”: “123456789”
}

What are you trying to do with that HTML?

It looks like a form.

You won’t be able to interact with it, as JavaScript is disabled in the visualize tab.

Therefore I suspect that the form and script block will just be ignored and produce a blank page.

1 Like

visualizer can display form elements and run scripts.

Looking at the visualizer code in the question, it’s trying to submit the form. I do not think that is supported!
Possibly because there would be security implications :person_shrugging: . Someone from Postman can provide an official reasoning.

After removing type="hidden" and the JavaScript code to submit the form, I’m able to view it in the visualizer.

With the submit code, I can see it’s being cancelled. I tested using both localhost and an external domain.

Visualizations can be debugged by right clicking on the visualization pane and selecting Inspect visualization
Screenshot 2023-10-17 at 10.02.56


I tested using similar code as @baha-bayar

// Not sure why we need this?
function fixHTML(html) {
    const fixedHTML = html.replace(/<input(.*?)>/g, '<input$1 />'); 
    const cleanedHTML = fixedHTML.replace(/onclick=".*?"/g, ''); 

    return cleanedHTML;
}

const htmlContent = pm.response.json().data; // HTML will be inside this field when using postman-echo.com
const fixedHTMLContent = fixHTML(htmlContent);

pm.visualizer.set(fixedHTMLContent);

And using postman-echo.com as follows

1 Like

@baha-bayar thinking more about your use-case. Doesn’t look like you are after visualizing the response, instead you want to submit the data in the form. Do clarify, if that’s not the case. :slight_smile:

Based on my assumption about your use-case, I suggest you parse the HTML response using cheerio library available within Postman’s sandbox, to setup a request directly in postman and execute that.

To get you started, the following code will return all the input elements inside the form:

const htmlContent = pm.response.json().htmlContent
const $ = cheerio.load(htmlContent);

let inputElements = $("form[id='test-3ds-form'] input");
let actionURL = $("form[id='test-3ds-form']")[0].attribs.action;

console.log(inputElements); // Check Postman's console to view the elements data
console.log(actionURL);

Next you can read the attribs field and extract the field name and value, store them in Environment (or Collection) variables. That can be used in the next Postman request. I leave this as an exercise for you.

You should then be able to view the response of the request directly within Postman, under the Preview tab.

1 Like

I think thats the reason , 2 years ago i try the same think but it works may be they blocked for some reason.

Thank you for long response :blush: .

My main purpose in here actually show the form and submit it.
It actually looks like

I send a request a API and thats the response of the API.

{
    "htmlContent": "<!doctype html>\n<html lang=\"en\">\n<head>\n    <title>iyzico Mock 3D-Secure Processing Page</title>\n</head>\n<body>\n<form id=\"iyzico-3ds-form\" action=\"https://sandbox-api.iyzipay.com/payment/mock/init3ds\" method=\"post\">\n    <input type=\"hidden\" name=\"orderId\" value=\"mock12-0791572182721940iyziord\">\n    <input type=\"hidden\" name=\"bin\" value=\"552879\">\n    <input type=\"hidden\" name=\"successUrl\" value=\"https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/success/3\">\n    <input type=\"hidden\" name=\"failureUrl\" value=\"https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/failure/3\">\n    <input type=\"hidden\" name=\"confirmationUrl\" value=\"https://sandbox-api.iyzipay.com/payment/mock/confirm3ds\">\n    <input type=\"hidden\" name=\"PaReq\" value=\"f00ad5a2-a580-4346-ba45-19647ca11bf0\">\n</form>\n<script type=\"text/javascript\">\n    document.getElementById(\"iyzico-3ds-form\").submit();\n</script>\n</body>\n</html>",
    "status": "success",
    "errorCode": null,
    "errorMessage": null,
    "errorGroup": null,
    "locale": "tr",
    "systemTime": 1697558195590,
    "conversationId": "123456789"
}

Normally visualize should look like this

resim

but it comes empty page

I use fixHtml function for getting html like this

<!doctype html>
<html lang="en">
<head>
    <title>iyzico Mock 3D-Secure Processing Page</title>
</head>
<body>
<form id="iyzico-3ds-form" action="https://sandbox-api.iyzipay.com/payment/mock/init3ds" method="post">
    <input type="hidden" name="orderId" value="mock12-7983036970477771iyziord" />
    <input type="hidden" name="bin" value="552879" />
    <input type="hidden" name="successUrl" value="https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/success/3" />
    <input type="hidden" name="failureUrl" value="https://sandbox-api.iyzipay.com/payment/iyzipos/callback3ds/failure/3" />
    <input type="hidden" name="confirmationUrl" value="https://sandbox-api.iyzipay.com/payment/mock/confirm3ds" />
    <input type="hidden" name="PaReq" value="9194771e-8fa8-4d6d-a7a9-840ec8b7c12f" />
</form>
<script type="text/javascript">
    document.getElementById("iyzico-3ds-form").submit();
</script>
</body>
</html>

I read the documentation of cheerio but it not actually helps me to visualize it.
If you have any idea for visualizing i will be happy to hear

This seems to visualize ok on my machine.

It looks like its triggering the form and pulling the data from iyzipay.

image

I didn’t realise that was possible. (Not sure you are meant to be able to do this).

I’m using the web client, not sure if this will work from the desktop client.

If you try and inspect the frame source, it takes you to the iyzpay mock.

https://sandbox-api.iyzipay.com/payment/mock/init3ds

what is your test script can you provide?

On a side note, this isn’t really visualizing the HTML you posted, but showing you what is returned when the form is submitted.

I don’t think this will work from the desktop client, as I’m sure I’ve seen posts where it mentions that this is disabled as the desktop client uses your local browser for the Visualize feature.

I guess its different for the web client, as you can’t disable JavaScript otherwise the rest of the app wouldn’t work.

It’s a bit of a security risk having this pull in data from outside Postman, that you haven’t specifically sent a Post request to.

Using the HTML from the post you provided, it will work without the fixHTML code you had previously.

So its nothing more than…

const htmlContent = pm.response.json().data;
pm.visualizer.set(htmlContent);

I’m doing the same as @xk0der in that I’m using Postman Echo to return the HTML based on your example.

I’ve just tested the desktop app and its not working there.

You can see if you inspect the visualization that its sat on your HTML code, which won’t show anything as the form elements are hidden.

Pretty sure that is expected behaviour. It should stay on the HTML that you provided to the visualizer, which as its showing hidden form data, shouldn’t show anything.

It’s not executing the JavaScript to submit the form to bring up the mock that you are expecting to see.

Saying that, you can use scripts in the HTML templates that you provide to the Visualizer, as I’ve used that a few times to reformat dates. So I don’t think JavaScript is completely disabled in the desktop version.

Not sure this should work from the web version either (but it does seem to at the moment).

Perhaps someone from Postman may be able to advise further on whether you are supposed to be able to do this or not.

2 Likes

Thank you for the response. I didn’t realize there was a difference between the Web Postman and the desktop version. I believe that’s why it’s not working

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.