26

I'm converting pages from an old format to new via Snippets. All was right in the world, up until I noticed Chrome's console "shortening" URL's so they would display better.

var url = "http://www.somewebsite.com/this/is/a/really/really/really/really/long/ass/url/that/will/be/cutoff/later/on/just/wait/wait/for/it/wait/for/it/there/here/are/some/query/strings?awwww=snap&this=is&really=happening"

console.log(url);

// Spits out
// "http://www.somewebsite.com/this/is/a/really/really/really/really/long/ass/u…r/it/there/here/are/some/query/strings?awwww=snap&this=is&really=happening"

These aren't the actual URL's, but you get the idea. Is there a way of removing formatting from Google Chrome's console area? This snag pretty much ruined all my plans, hoping to not have to use a headless browser just to get raw text output. :-\

3
  • what plans is this ruining? why not just perform some comparison in the console like .indexOf, ==, !=, etc.. and evaluate that simple output instead Oct 4, 2013 at 15:00
  • @RobertLevy I'm using Chrome snippets to get content off a series of old pages into a parseable format. Not really doing anything programmatic with it other than to format the innerHTML to what I need. Oct 4, 2013 at 15:02
  • @san.chez I updated the URL. The one in my example wasn't large enough, it happens with or without extensions. Oct 4, 2013 at 15:05

5 Answers 5

26

One workaround I found wasn't to log the actual values I was wanting. Instead I set it to a window variable and use copy(window.varToCopy)

copy() is a native Chrome function you can use in the console to copy the data to your clipboard. Luckily it seems that it doesn't format anything you pass into it, so I can then get the actual URL rather than the broken one.

This is only a workaround, hopefully someone knows how to remove console formatting!

3
  • not really a workaround, that's the way to go - at least for moderate sized snippets
    – Andrea
    Oct 29, 2014 at 6:58
  • This really works for exporting objects with long urls to the clipboard. copy(JSON.stringify(someObj)). For example to export mock data into a test or during development to get predictable data. It actually works without stringifying the object first too. copy(someObj).
    – Viktor
    Apr 12, 2016 at 7:27
  • This also works in Firefox (unlike using console.dir as suggested in another answer)
    – Motin
    Jan 21, 2021 at 12:13
25

My workaround is to use console.dir(url);. It isn't designed for this purpose, but it definitely does the trick:

enter image description here

You can't really open the hierarchical listing, but you don't need to anyway.

4
  • 1
    I wish I had thought of this, haha! Good work around though, totally works. Oct 22, 2014 at 14:13
  • this tip just made my day!
    – user257319
    Mar 19, 2015 at 21:55
  • I couldn't figure out why my variable wasn't working but ONLY when I used regex or split and joined a string and NOT when I used replace... Experienced this in chrome and ff and it logged a long valid link before... Only when it starts with "tps://" but "ps://" is valid... Wasted hours of my life on this crap... console.dir works perfectly!
    – Justin
    May 7, 2022 at 3:42
  • It doesn't work in Firefox.
    – DaWe
    Jun 20, 2022 at 21:52
2

I ran into this issue when I had a long array of long urls. Nothing of the above helped.

The solution I finally came up with is: console.dir(JSON.stringify(urls))

0

When a URL is displayed in the Chrome Javascript console, there are some context menu (i.e. right-click menu) options to interact with that url. If all you want is to copy and paste the full text of the URL to another location for viewing, you can right-click on the URL in the console and select "Copy Link Address". Then, just paste anywhere - even back into the Javascript console, if you want! - and the full, unshortened URL is there for your viewing enjoyment.

While this doesn't disable Chrome's URL-shortening behavior, it is a more comfortable workaround to me than inserting Chrome-specific Javascript into my code.

3
  • Ahh, that's nice. Before there was no such options, iirc it outputted to the console as a concatenated string. Feb 21, 2014 at 15:13
  • 1
    This answer has received several downvotes with no explanation as to why. Please explain when you downvote.
    – Zeimyth
    Nov 5, 2014 at 20:05
  • The downvotes are pretty old at this point, I doubt the original voters will see this. I'd imagine the reasoning behind them is that it doesn't fix the issue with code. You'd also mentioned not wanting to use Chrome-specific code, but snippets are by default (unless FF added that ability recently). Nov 5, 2014 at 20:10
0

I just had the same problem. I ended up using this little workaround, making the url a non-url by removing leading http/https:

console.log(url.replace(/^https?:\/\//,""));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.