I have a bookmarklet that allows me to wrap any function and insert a debugger
statement before it is called.
It works fine, but since the bookmarklet is a single line debugger stops somewhere in the middle of a long string of code and I need to scroll to find the breakpoint.
How can I insert a new line character after the debugger
statement so that when it's encountered the code in the console is split into two lines?
The \n
and literal newline character copied from a textarea into the bookmarklet don't split lines in the debugger.
Generally, it is best to URL-encode a bookmarklet before storing in a bookmark. So you can have a multiline bookmarklet simply by encoding the newlines, as demonstrated by this: encodeURIComponent("alert('line1');\nalert('line2');")
That answers the question as you asked it, but I'm not sure if this is your real problem. If you provide example code I might be able to give further advice.