1

Plenty of Snippets don't need HTML and just put their results in the console. See an example below.

The problem is that the console only displays the last 50 lines -- which completely borks some snippets (example below).

Possible fixes:

  1. Don't limit the console output. Or increase the output to a more reasonable amount like 500 lines.
    This gives space for the most ambitious demos (that are likely to be read) while still guarding against runaway console dumps.
  2. Give the user an option to keep the first N lines, rather than the last.
  3. Maybe keep 20 or 50 lines as a default, but give the user (post writer) an option to show up to 500 lines.
  4. Also implement FR: Allow the stack snippets console to be maximized.

Real world example: (from an answer I was working on)

This snippet:

var srchTag     = "reputation-graph";
const cYourKey  = "";  //  "&key=3TIJXXXXXXXXXXXXXZB0AA((";  // key is optional but very recommended
const cMaxPages = 5;  //  WARNING:  Only set this higher once you are sure the code works as you want it.
var tagStats    = {};

getPageOfQuestions (1);
function getPageOfQuestions (pageNum) {
    fetch (
        `https://api.stackexchange.com/2.2/questions?tagged=${srchTag}&page=${pageNum}&pagesize=100&sort=creation&order=asc&site=meta&filter=!-W2eZY)NCj(NnIzhnVP6${cYourKey}`
    )
    .then (function (response) {
        if (response.ok)  return response.json();
        throw new Error (`API problem: Error ${response.status}, ${response.statusText}`);
    } )
    .then (function (rJsn) {
        if (rJsn.backoff  ||  rJsn.error_id) {
            throw new Error (`From API: Backoff ${rJsn.backoff}, Error: ${rJsn.error_id}, ${rJsn.error_message}, ${rJsn.error_name}`);
        }
        console.log (`Quota remaining: ${rJsn.quota_remaining}; Items found: ${rJsn.items.length}`);

        let allDone     = ! rJsn.has_more;
        let zQuestions  = rJsn.items;
        for (let qstn of zQuestions) {
            for (let zTag of qstn.tags) {
                let tagStat     = (tagStats[zTag] || 0) + 1;
                tagStats[zTag]  = tagStat;
            }
        }
        if (rJsn.has_more) {
            let newPageNm  = rJsn.page + 1;
            if (newPageNm <= cMaxPages)
                getPageOfQuestions (newPageNm);
            else
                allDone = true;
        }
        if (allDone) {
            //--- Do final processing here...
            let tagsByPop = Object.keys (tagStats).sort ( (a, b) => (tagStats[b] - tagStats[a]) );
            for (let zTag of tagsByPop) {
                console.log ( (zTag + ":").padEnd(36),  tagStats[zTag]);   //  35 is max tagName length.
            }
        }
    } );
};
.as-console-wrapper { max-height: 100% !important; top: 0; }

Should display results like:

Quota remaining: 9951; Items found: 100
Quota remaining: 9951; Items found: 97
reputation-graph:                    197
bug:                                 107
reputation:                          48
...  ...
reputation-history:                  1
offensive:                           1

Instead it displays:

bad console truncation

-- which discards the most important results.

  • As a work around, you can encourage users to check their browser consoles where all output lines should be displayed. – Nick A Jun 19 at 0:18
  • 1
    @NickA, that's a small console-ation... – Awesome Poodles Jun 19 at 1:11

You must log in to answer this question.

Browse other questions tagged .