Skip to main content
292 votes
Accepted

I've been told to create a "runnable" example with "Stack Snippets". How do I do that?

Stack Snippets are an on-site tool similar to jsfiddle.net, codepen.io or plnkr.co. They're more limited than those tools, but they have the advantage of being on-site, so your code/markup is in your ...
250 votes
Accepted

How do I create a React Stack Snippet with JSX support?

Here's a step-by-step guide, first summary, then details with pictures. There are a couple of live demonstration snippets after the detailed instructions. Summary: Open the Stack Snippets editor by ...
43 votes
Accepted

Is this 'Run code snippet' with payload an attempt to infect SO users' machines with a virus?

At the moment, Stack Snippets are, to the best knowledge of experts who've considered the problem (both SE employees and standard users like ourselves), completely sandboxed and pretty safe to run. ...
CertainPerformance's user avatar
40 votes
Accepted

Stack Overflow reputation and profile link in email sign

You could use Flair. Navigate to your profile -> "Edit Profile and Settings" -> Flair (under the Site Settings subheader). There you'll find an HTML snippet for a generated image with contains your ...
Mureinik's user avatar
  • 310k
38 votes
Accepted

Unrunnable/useless Stack Snippets in Suggested Edits

You have four options. The first three are in order of most to least recommended: You can flag one of the posts they've edited for moderator intervention and ask a moderator to intervene. I've done ...
BSMP's user avatar
  • 4,786
38 votes

How to deal with a user reformatting snippet data to be in a single line

When the data is quite long, verbatim from the question (where the user left it expanded), not an important part of the answer, and the edits are to the answers that copied the extremely long sample ...
Ryan M's user avatar
  • 20k
36 votes
Accepted

Guideline on edits that only add/remove stack snippet

Edits adding a snippet If the snippet demonstrates the issue the OP is asking about when you click Run code snippet, approve. If not, reject. Edits removing a snippet If the snippet demonstrates ...
T.J. Crowder's user avatar
35 votes
Accepted

Why won't this snippet with async await work here on Stack Overflow snippet editor?

Update: This is fixed as of Oct 3 2024, see the updates in this bug report (which SE called a "feature request"). The problem is that the version of babel-standalone used by Stack Snippets ...
T.J. Crowder's user avatar
34 votes

How can I add code to the head element when posting a code snippet?

If dynamically creating the <meta> tag isn't enough, there's a way to put the tag in directly, without JavaScript, through a hack. The text in the CodeMirror textareas will be inserted verbatim ...
CertainPerformance's user avatar
34 votes

How do I demonstrate a preventDefault problem on a link in a Stack Snippet?

Although Stack Snippets prevent you navigating to a different document (or opening a new window), you can navigate within a document using a fragment identifier, which is all you need to demonstrate ...
T.J. Crowder's user avatar
30 votes
Accepted

All my code is properly formatted, yet I am unable to post an answer due to unformatted code. Why?

In the first version of this question where you post your original markdown, you had indented code only one line down from your quoted text. When posting blocks of code there has to be a blank line ...
BSMP's user avatar
  • 4,786
27 votes
Accepted

Code snippets are not runnable on the Stack Overflow mobile website

I agree that this distinction should be removed. Nowadays, mobile devices that can run JS are perfectly capable of running it properly. The only issue SO would have with implementing this, would be ...
Cerbrus's user avatar
  • 72.6k
27 votes
Accepted

Stack Snippets that assign `var location` at the top scope redirect and produce “Server Error in '/' Application.”

It's due to the var location, which assigns to window.location and attempts to replace the page. But you assigned an object to location, resulting in a request to https://stacksnippets.net/[object%...
CertainPerformance's user avatar
26 votes

Sharing data between snippets, such as test inputs

Live shared data between Question and Answers: Don't do it We should not have a shared snippet context between the question and answers. Doing so inherently sets up a dependency on the question for ...
Makyen's user avatar
  • 33.2k
24 votes
Accepted

Can we have an option to add more files in stack snippet like Plunker?

duplode alluded to it in the comments, but it's probably more concise to distill this point. This would be extraordinarily prone to misuse. Here's why: We already have users who believe taking a ...
Makoto's user avatar
  • 106k
23 votes
Accepted

How to provide additional code to comment an answer?

Or should I edit my question (risking that my question gets longer and longer)? Do not edit and scope-creep your original question. If you have additional requirements exposed by the answer, ask a ...
ryanyuyu's user avatar
  • 6,476
23 votes
Accepted

How are Stack Snippets implemented?

The origin of the iframe is null because of the iframe's sandbox attribute (and the absence of the allow-same-origin clause). Since the iframe's origin is null it can't access its .parent and thus can'...
Kaiido's user avatar
  • 136k
23 votes
Accepted

Should I suggest edits to transform code blocks into Stack Snippets for HTML/CSS/JS questions?

I think I'll avoid suggesting adding them however unless there are other fixes I can make at the same time... Daniel Black That's probably the safest thing to do. I would also add: If it relies on ...
BSMP's user avatar
  • 4,786
22 votes
Accepted

How to improve questions to make them easier to comprehend?

I have two suggestions to offer. Both involve putting psychological distance between yourself and the question. That distance gives you a valuable perspective on how other people will view and ...
jscs's user avatar
  • 64k
22 votes

How to make a working snippet with a library not available in HTTPS?

The best solution is to find an HTTPS based source for the file you desire to use. Files in GitHub repositories are always available via HTTPS jsDelivr (instructions for GitHub links) Example: ...
Makyen's user avatar
  • 33.2k
22 votes
Accepted

Stack Snippets Console can't output ES6 data types

I don't know that we can really expand those weak structures. That said, a newer version of the console visualizer was mentioned back in January. That particular version replaced our JSON-flavored ...
canon's user avatar
  • 41.6k
20 votes
Accepted

How to edit a snippet once inserted in the Stack Overflow answer?

You have a link, "edit the above snippet" under the "Run code snippet" button when you edit your post.
Alon Eitan's user avatar
20 votes
Accepted

How to use "code snippet" vs "code block"

Your assumption is correct, see this blog post for more information. Not all users know how to format their code. If you come through such posts, simply edit them. Removing the useless code snippet ...
Maroun's user avatar
  • 95.8k
20 votes
Accepted

Is it possible to have Python code snippets in Stack Overflow?

This is not feasible. Stack snippets run entirely in the browser. You can't run Python in everyone's browser, not the CPython (main) implementation. Python is a very, very rich ecosystem, with ...
Martijn Pieters's user avatar
20 votes
Accepted

Are Stack Snippets always safe to run?

No, not yet. First, we need RFC 3514 to be adopted that would require evil doers on the internet to set the evil bit in IPv4 packets to signify they are evil. RFC 3514 is not a technical requirement ...
VLAZ's user avatar
  • 28.8k
19 votes

Sandbox the console separately?

Don't change this. I regularly see users leverage this to change the console output: console.log("Gee,\n\nthis\n\nis\n\na\n\nlo\no\no\no\no\no\no\nng\n\nstring!"); .as-console-wrapper { max-...
Cerbrus's user avatar
  • 72.6k
19 votes
Accepted

Is it bad to introduce snippet formatting?

The post was rejected by the OP, with the Reject and Edit button. This button carries an automatic reason. Given that the user is not that experienced with Stack Overflow yet, and has made several ...
Martijn Pieters's user avatar
18 votes
Accepted

Removing Fiddle links

No, these links needs to be preserved. I'm not a lawyer but I do know that JSFiddle uses a different license for their code submission then SE does. Only the OP is allowed to copy over the code from a ...
rene's user avatar
  • 42.3k
18 votes

Is there an option to run my code snippet automatically when opening Stack Overflow questions?

No, there is no such option. I also think such option would be open to abuse. Some argue you will miss the juicy animation as it is already done once the snippet scrolls into view. I prefer to click a ...
rene's user avatar
  • 42.3k
18 votes
Accepted

Add a warning about snippets being dangerous when they are run

So can Stack Snippets be confirmation-to-run when they have dangerous items (e.g. infinite loops, cookies, or infinite server requests)? This is provably impossible. It would require solving the ...
Ryan M's user avatar
  • 20k

Only top scored, non community-wiki answers of a minimum length are eligible