50

Code snippets are shown as "code blocks", but without the Run button on mobile devices. (e.g. on Chrome / Android phone).

It would sometimes be very useful to be able to run code snippets on mobile.

Examples:

  • I don't see why running this code snippet from this answer should be possible only on desktop browsers, and not on mobile browsers. Running such a code snippet on both could be equally useful.

  • It would be particularly interesting to be able to run code snippets from questions with tag

Could we enable code snippets Run button on the mobile version of SO?

0

4 Answers 4

27

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 the layout on smaller screens, but I'm sure they can figure that one out.

3

I agree it's 2018 and would be useful to allow snippets on mobile. I'd suggest the option to open them, at least the running version, if not also the editing version, in their own tab.

As an example right now I want to ask a question about disabling scrolling on iOS Safari 11.3.1 (which seems to be broken as no previous answers work). I'd like to post working snippets. I can't because it's impossible to run them in a mobile context so I have to setup a github repo and use github pages or set them up somewhere else. Even codepen, jsbin, jsfiddle, can't do this currently which makes it hard to ask questions about mobile html topics on SO. Well, not hard to ask but hard for people to help out since they too end up having to setup some other environment with which to test. This happens often where you want to post an MCVE except the only way to run the MCVE is for the user to setup their own server with your snippet.

It seems ideally you could click "run snippet in new tab" which would run the snippet not in an iframe but as the top frame. You should also be able to set the meta tags since there are meta tags that change mobile browser behavior (probably the html part already covers that) but I can't check since I can't run snippets outside a frame. Settings like scrolling=no and user-scalable=no etc...

Note that pages can send messages across tabs if on the same domain (not sure that works everywhere).

That means for example even if a snippet editor opened in a new tab it can send it's snippet content back to the main tab directly.

Pages can also open tabs using blobs meaning no round trip to the server is needed when pressing run (though async sending the current snippet to the server might be good for recovering snippet state after a crash).

Example of both. Would have used a snippet but snippets disable popups. That restriction also seems like it should be lifted since it's yet another feature people want to be able to discuss and debug using snippets.

1
  • There's a question today about some code that doesn't run in mobile Safari. I wanted to verify the problem, but can't run the code snippet.
    – Barmar
    Jan 8, 2020 at 22:11
-11

I don't think it is worth implementing this.

You can still run snippets in the Desktop edition of Stack Overflow, even from a Mobile.

A full site pseudo-link is available at the bottom of any SE page.


And to add a bit more argumentation:

As a fervent user of StackSnippets, I prepare mine for the reduced view that you get from the page, and sometimes for the full page view.
Both views can be tested when writing the post, but if such a feature were to be implemented, it would have to have different proportions than in the desktop edition, and I wouldn't be able to test this set of proportions while writing my posts.

2
  • 10
    Mobile web browsing will always be sub-optimal. We shouldn't block a feature this practical, just because it might not look good on some cases.
    – Cerbrus
    Feb 21, 2018 at 7:59
  • It seems people are missing the point: You can still run snippets in the Desktop edition of Stack Overflow, even from a Mobile.. This desktop edition isn't a full zoomed out display. It is a responsive design and looks better in mobile than the mobile website. Scroll down to the bottom > Enable responsiveness(It would be great, if it is enabled for all users by default.)
    – TheMaster
    Aug 25, 2020 at 4:44
-14

If all you're looking to do is test the mobile responsiveness of your functionality...then there are two things which don't directly involve Stack Overflow that can be done.

  • Run the code locally using your browser's responsive toolkit
  • Run the code as a snippet in full screen using your browser's responsive toolkit

Allowing mobile devices to run what is essentially arbitrary JavaScript sounds like a nightmare for device longevity and safety. Worse, you have to contend with slightly different Webkits running or the quirks of the mobile browser and its JavaScript engine. This creates unnecessary support work for little gain.

13
  • 3
    There might be a misunderstanding, but I'm not speaking about how to test the mobile responsiveness of my functionality (for my own testing I don't use SO of course, I use local tools). I'm not sure to understand your answer, but I don't see any valid argument why running this code snippet from a 3900+ upvoted answer should be possible only on desktop browsers, and not on mobile browsers.
    – Basj
    Feb 20, 2018 at 19:47
  • 1
    @Basj: You now introduce a whole host of new browsers for Stack Overflow to support for very little gain. Most of the flagships use some variant of Chrome or Firefox for the truly adventurous, but there are some users out there with older or outdated or horrendously patched versions of Webkit, none the wiser. It makes for more work for again, little gain. The mobile responsiveness piece I feel I made my concise point on; if you want to thoroughly test that, then you're going to want to not do it on a third-party site.
    – Makoto
    Feb 20, 2018 at 19:59
  • 3
    I respectfully disagree @Makoto, "People have outdated mobile browsers or horrendously patched versions" is not a valid agument for preventing all people to run a code snippet on mobile.
    – Basj
    Feb 20, 2018 at 20:03
  • 1
    Example of use case: 1) I read a good answer on SO (on desktop browser), I run the snippet, it works. 2) After some further research (checking documentation, etc.), I implement it on my website. 3) I visit my website on mobile, it doesn't work... ouch.... This could have been avoided by adding 1bis) I read the same answer on my mobile, run the snippet, it doesn't work => now I know that this solution is a desktop-only solution.
    – Basj
    Feb 20, 2018 at 20:05
  • @Basj: At one point in my career I worked for a company that required that we support IE5, up until it finally became enough of a security concern (in terms of SSL and SSL alone) that we had to abandon it. Our development efforts to support and retrofit any work we had with that older browser (and other older browsers like it) cost the company on the order of hundreds of thousands of dollars. If you can choose the browsers you want to support, choose them!
    – Makoto
    Feb 20, 2018 at 20:06
  • @Basj: Additionally your use case is a typical yet unfortunate side-effect of using Stack Overflow; copying this code in to see if it works for all of your use cases without actually taking the time to see what all of your use cases are. I confess to being guilty to it too from time to time. Don't put the onus of mobile validation on Stack Overflow.
    – Makoto
    Feb 20, 2018 at 20:07
  • Once again, with all my respect @Makoto, I don't see why a reader of SO on a phone shouldn't be allowed to run this code snippet. (By reading it on phone, he doesn't even know there is a code snippet, strangely).
    – Basj
    Feb 20, 2018 at 20:09
  • @Basj: So you don't see a problem with including more browsers for support? You don't see any issues with making Stack Overflow's snippet project ultimately responsible for any quirks between mobile and desktop snippet execution? Well, alright then. I suppose I can't convince you. But I will state I remain unconvinced that this is worth the risk and development effort as opposed to fixing a few other things around here that need fixing.
    – Makoto
    Feb 20, 2018 at 20:12
  • 4
    "Allowing mobile devices to run what is essentially arbitrary JavaScript sounds like a nightmare for device longevity and safety." So, are you saying all browsers on all mobile devices should just block JavaScript? Imo, this falls under the category Irrational paranoia. Were this answer posted 5 years ago, I'd have agreed, but nowadays, the vast majority of mobile devices are perfectly capable of properly running JS.
    – Cerbrus
    Feb 21, 2018 at 7:53
  • @Cerbrus: I recognize that all sites utilize JavaScript, but the "arbitrary" factor comes in from others writing code that runs on Stack Overflow (in some capacity) that doesn't really impact how you interact with Stack Overflow, which is...unsettling. That code could be dangerous; it could overflow your phone's tiny memory capacity at whim. Again, I recognize that there are other sites that are perfectly capable of doing this too, but I remain unconvinced that making this easier to execute would be a wise decision.
    – Makoto
    Feb 21, 2018 at 21:05
  • 5
    @Makoto Why should I be unable to run a snippet that executes JavaScript on my phone? The JavaScript will only run when I click/tap Run snippet.The issues you are talking about exist for any website you might visit. And a very large portion of the JavaScript running on those websites (e.g. frameworks, libraries, etc.) is not written by the owners/webmasters/admins. And most websites run some form of JavaScript for analytics (e.g. Google Analytics). Most browsers in existence support disabling JavaScript if you don't want to run any other code. Do that if you don't care about functionality.
    – Toothbrush
    Feb 21, 2018 at 22:25
  • 1
    @Makoto But then why do you trust the browser itself? Browsers and the libraries they depend on are regularly patched to fix security issues.
    – Toothbrush
    Feb 21, 2018 at 22:31
  • 3
    @Makoto: Why the distinction between mobile and desktop? You're not implying mobile browsers are less capable of handling malicious JS, are you? All significant browsers have methods of dealing with such scripts. Besides, this is SO. Any code on here that's actually malicious, will be curated.
    – Cerbrus
    Feb 22, 2018 at 7:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .