Copy the request URL to the clipboard

If you didn’t want to keep going to the Postman Console, you could have a go with this? Add this template to the Tests tab and it should show the URL and give you a “copy to clipboard” button in the Visualizer. :smile:

let resolvedURL = pm.request.url.toString();

let template = `
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
</head>
<body>
    <div>
    <div>
        <pre><code style="width:max-content!important;" id="copyText">${resolvedURL}</code></pre>
    </div>
    <button class="copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyText" style="background:green;color:white;">Copy to Clipboard</button>
    </div>
</body>
</html>
<script>
    var clipboard = new ClipboardJS('.copyButton');

    clipboard.on('success', function(e) {
        e.clearSelection();
        e.trigger.textContent = '✔ Copied!';
        window.setTimeout(function() {
            e.trigger.textContent = 'Copy to Clipboard';
        }, 2000);
    });
    clipboard.on('error', function(e) {
        e.clearSelection();
        e.trigger.textContent = '✗ Not Copied';
        window.setTimeout(function() {
            e.trigger.textContent = 'Copy to Clipboard';
        }, 2000);
    });

</script>`

pm.visualizer.set(template, pm.response.json())
3 Likes