r/webdev • • Jun 01 '21 • Heart Eyes 1

Resource That feeling when you first discovered `document.designMode`

8.3k Upvotes

260 comments sorted by

285

u/shmorky Jun 01 '21

Why 'on' tho?

Why not just true?

146

u/ishtiaq156 Jun 01 '21

this is actually a good futureproofing approach. designMode used to have three states https://developer.mozilla.org/en-US/docs/Web/API/Document/designMode

38

u/[deleted] Jun 01 '21

I mean, they could support boolean values as well if they wanted to... It's a dynamically typed language after all

22

u/thelethargicdog front-end Jun 01 '21

For consistency. DOM APIs have always been consistent with the return types.

7

u/[deleted] Jun 01 '21

I see, meh...

Interestingly, I discovered that many DOM APIs will automatically downcase strings.

> document.designMode = 'ON'
"ON"
> document.designMode
"on"

2

u/[deleted] Jun 02 '21

I'm assuming it's more a matter of the underlying C++ fields being strongly typed than wanting API users to see consistent types?

1

u/BHSPitMonkey Jun 02 '21

It also sucks because your third (or fourth, or...) states happen to all be truthy.

→ More replies (1)

1

u/10eleven12 Jun 02 '21

Who cares.

1

u/DooDooSlinger Jun 02 '21

Or you know, do it correctly

3

u/-IoI- Sharepoint Jun 02 '21

I don't get it.. are we depreciating booleans in the future?

7

u/Ullallulloo Jun 02 '21

It could have a "extra" design mode or "partial" design mode or something in the future. If something can only be true or false, you can't easily change stuff about it.

631

u/[deleted] Jun 01 '21

Mindblowing! This is awesome!

Much much much better than choosing one element and trying to edit the text or HTML over developer tools

154

u/JapanEngineer Jun 01 '21

That’s what I’ve been doing the last 3 years...

30

u/zaitsman Jun 02 '21

Take 10 years here

76

u/KingKongOfSilver Jun 02 '21

So all this "design" mode can do is edit texts? I guess my expectations were a bit too high of a mode called "designMode"... Seems quite useless to be honest

13

u/[deleted] Jun 02 '21 edited Jun 02 '21

Yeah, it's only editing text, but you can also organize your elements and put them in different locations with simple copy/cut-paste. I believe that makes it more useful.

7

u/Ph0X Jun 03 '21

If you want a real "design mode", check out VisBug

https://visbug.web.app/

19

u/Hairy_Shine_6629 Jun 05 '21

I just edited your comment. I can control ANYTHING

12

u/Hairy_Shine_6629 Jun 05 '21

I just gave your post 696969 upvotes with this awesome trick. You're welcome

3

u/[deleted] Jun 05 '21

Hahah, thanks hairy shine!

221

u/[deleted] Jun 01 '21

Also don't miss out on the contentEditable="true" attribute to target specific element.

19

u/JasperNykanen := Jun 02 '21

<div contentEditable></div>

Works just the same, the explicit ="true" is considered an anti-pattern.

1

u/etvorolim Jun 22 '21

Would it be useful in creating a WYSIWYG application?

→ More replies (2)

77

u/kylegetsspam Jun 02 '21

And don't forget that Chrome is a conflict of interest, a browser made by a marketing firm, and is selling all your data.

https://amifloced.org/

63

u/TheSpiffySpaceman Jun 02 '21

We all know; we still have to support it to make the paycheck though.

24

u/Sackadelic Jun 02 '21

I find FF’s dev tools just as good, better in some departments.

8

u/[deleted] Jun 02 '21

How is that relevant to the comment you're responding to?

10

u/Sackadelic Jun 02 '21

I misunderstood. Thought that the poster was saying basically “we have to use chrome for development”

4

u/[deleted] Jun 02 '21

Gotcha

→ More replies (2)

32

u/nikehat Jun 02 '21

What does this have to do with anything from this post?

4

u/Ph0X Jun 03 '21

And how does it have 60+ upvotes? This is literally what downvotes are for, not for things you disagree with, but for offtopic unrelated comments like that.

7

u/i_took_your_username Jun 02 '21

It has nothing to do with the post or the comment he replied to. /u/kylegetsspam only posts comments about things he's complaining about or people he's better than.

5

u/teacoat___ Jun 02 '21

Meh I still prefer it

→ More replies (7)

0

u/[deleted] Jun 01 '21

[deleted]

111

u/BazilExposition Jun 01 '21

It's an amazing fresh feature - it just appeared on IE6 in 2001!

35

u/ClassicPart Jun 01 '21

Can't find anything

Literally the first result for contenteditable on both Google and Duck Duck Go will give you the link to MDN, which has more information than you will ever want to know about it.

I assume you couldn't find anything because you didn't actually bother searching and instead expected everyone to spoon-feed you.

23

u/bgeyts667 Jun 01 '21

20

u/mypetocean Jun 01 '21

As someone who used this feature over the weekend (for use in a CSS teaching tool), a few words of warning about contentEditable:

  • The default behavior will insert a DIV or SPAN every time you hit Enter/Return. The only way to change this behavior natively is browser-specific (Chrome has contentEditable=plaintext-only). The only other way around this, is to use the Shift+Enter hotkey to insert a newline character without HTML formatting.

  • In fact, pretty much everything interesting about this HTML attribute is the browser-specific implementations. That also means... That's right: you should mostly avoid using it. My educational case works because I am using the page for a screenshared demo.

  • The Tab key maintains its element focus behavior. So if you want Tab to insert a tab character or a soft-tab, you need to listen for Tab keypresses, do event.preventDefault(), then do an execCommand to insert text at the location of the text cursor caret: document.execCommand("insertText", false, " ")

5

u/ManiacsThriftJewels Jun 01 '21

Nah bruh, execCommand is deprecated. You need to getSelection, check it's a caret, convert to a range, make sure the container's a text node, split the text node, insert a new text node containing a tab in the parent element after the preceding text node, and if you're nice you might even normalise the parent element...

But wait, that's marked as experimental and prone to change...

2

u/mypetocean Jun 02 '21

Exactly. There is no non-bodged, cross-browser, or standards-compliant way to do this stuff.

This weekend, I so happen to have been privileged to ignore those concerns because only I had to be burdened with them.

→ More replies (2)

18

u/dons90 Jun 01 '21

Wait where did you even look? contentEditable is very easy to find information on 🤔

25

u/MindlessSponge javascript Jun 01 '21

It's much easier to just say you can't find it, then someone will reply with exactly what you want to know - rather than "wasting your time" looking it up and reading all that extraneous detail.

Same logic as posting the wrong answer instead of asking for the right answer, I suppose.

7

u/Noch_ein_Kamel Jun 01 '21

contentEditable let's you eat the content.

edit: also it's called Murphys Law

6

u/snailiens Jun 01 '21
contentEdible
→ More replies (2)

1

u/evilgwyn Jun 02 '21

Lol the internet is so dumb it doesn't even have any content editable documentation

0

u/[deleted] Jun 01 '21

[deleted]

2

u/dons90 Jun 01 '21

he was probably expecting it to be a console command

Well that may be true, but if a console command doesn't immediately come up, the next step is the search engine no?

0

u/[deleted] Jun 01 '21

[deleted]

→ More replies (1)

1

u/IlllIllllllllllIlllI Jun 02 '21

Relevant username

193

u/oompahlumpa Jun 01 '21

They call it design mode but it seems like all you can do is edit text?

184

u/human_brain_whore Jun 01 '21 edited Jun 27 '23

Reddit's API changes and their overall horrible behaviour is why this comment is now edited. -- mass edited with redact.dev

65

u/NotChristina Jun 01 '21

The latter is 100% what I’ll use this for. I had no idea it was a thing. I do a lot of on-the-fly demos for internet stakeholders and many times they just want screenshots. This will definitely be a timesaver.

28

u/su-z-six Jun 01 '21

I'd say about once a week I open up dev tools in a stakeholder meeting to demo a simple HTML edit and create a screenshot.

This will only save me a few seconds, but more importantly I don't have to jump into code while screen sharing. That is always when the top level leadership loses interest.

5

u/_Invictuz Jun 01 '21

Lol, not high level enough!

→ More replies (2)

8

u/Tokogogoloshe Jun 02 '21

But can you save those changes? I’m just curious.

7

u/TheAnxiousDeveloper Jun 02 '21

I think you simply edit the source code. There is no way that a client side modification (on the aesthetic) is going to do it for you.

1

u/MarmotOnTheRocks Jun 02 '21

Nope, it reverts to the original content as soon as you reload the page. It's just a visual tool on the client side.

0

u/[deleted] Jun 02 '21

[deleted]

2

u/etvorolim Jun 22 '21

That's very interesting. I was thinking about that. Just having a save button that calls for a function that saves the inner HTML of an array of editable elements.

Also, ESP32 ftw.

0

u/[deleted] Jun 22 '21

[deleted]

→ More replies (1)

6

u/greghuels Jun 01 '21

I'm sure there's also good use in seeing how responsive different content is to window size changes in the event that the content is dynamic. Could also just edit the html for that though

→ More replies (2)

2

u/rich97 Jun 02 '21

Question: if you’re using file system mapping and you edit using design mode does that reflect on the file system once you saved?

109

u/xSypRo Jun 01 '21

Same, i don’t really understand the hype. Am i missing something?

13

u/jk3us Jun 01 '21

It's mainly for faking screenshots of Bitcoin balances.

1

u/KamikazeHamster Jun 02 '21

Do a demo on a website with a client, they ask what it would look like if <x> is worded different or what it would look like if <y> is in a different location. No need to open the dev tools and fiddle with the source code - you can literally highlight the component you want, cut it and paste it somewhere else.

1

u/[deleted] Jun 02 '21

Yeah, this isn't useful for any js generated website, but could be nice if you're showing a page to someone who isn't tech savvy and they want something minor changed.

0

u/[deleted] Jun 01 '21

[deleted]

18

u/xSypRo Jun 01 '21

I mostly use dev tools to mess around with sizing and colors. But why edit the text content like that?

36

u/DoctorProfessorTaco Jun 01 '21

In my case I’m often building out a frontend before I have data available (and occasionally before I even know exactly what the data will look like or what pieces of data I’ll have), and I’ll want to make sure it looks good and operates properly when displaying several different examples of possible data so I’ll have as few changes as possible when I actually get real data. Now to do that, I could look at the page with one example, edit the code, recompile, and look at the new example, or I could edit the text in the element inspector, but being able to just type it out directly on the page makes it way easier than either of those options and allows me to try many different examples quickly. It’s also nice from a design perspective if I want to try out different descriptions or labels or titles without having to edit the element directly or edit my code.

4

u/undercover_geek Jun 02 '21

This is by far the best argument for it's use I've seen in the comments.

→ More replies (1)

14

u/SoBoredAtWork Jun 01 '21

Make quick mocks for A/B testing. Proof of concept screenshots. Fake data without having to go into the source. Etc.

3

u/Cafuzzler Jun 02 '21

Off the top of my head I think one possible practical use could be checking how your design handles custom user names: What happens if the username is 40 characters long, or uses emojis, or uses an arabic or chinese script, or someone tries to use crazy g̴̨͛͠ḻ̵̞̂i̸̞͔̊ṫ̴̘c̸̮͖̔h̶̖̊͜ text. You can test all of that, and test it with dynamic resolution and mobile formatting, on the frontend side of things without refreshing or reloading the page. Of course there are plenty of other ways to test those things too, but it's an option that's unobtrusively there if you need it.

3

u/AcousticDan Jun 01 '21

Neat, what's the problem one would solve with this? Tricking old ladies out of their hard earned cash?

7

u/pagelab Jun 01 '21

I use this to grab screenshots of restricted areas that have information I need to change.

→ More replies (2)
→ More replies (2)

2

u/npmbad Jun 01 '21

It's only use I found was trying to find good headlines for my landing pages. It really did help in that case.

2

u/col-summers Jun 02 '21

More like copyEditingMode

3

u/PM_YOUR_FIRST_LAYER Jun 01 '21

Yeah with hot reloading being a thing it's kinda underwhelming.

1

u/Ph0X Jun 03 '21

To be fair, back when it was added, the web was basically just more or less pure html and websites were all mostly text.

24

u/unkill_009 Jun 01 '21

So if I get this correctly, will the CSS/HTML code change too? and I just need to copy it in my VS Code

23

u/JBlitzen Jun 01 '21

It’ll change, but there’s no standard between browsers or versions regarding what it will change TO, so be careful with it.

Getting the new code out dynamically can also be a challenge since not all dynamic code is aware of user changes.

3

u/unkill_009 Jun 02 '21

I see, appreciate the info!

14

u/montrayjak Jun 01 '21

In the dev tools, go to the Sources tab -> Filesystem (top left) and Add folder to workspace. Then your changes will be saved. Code too (ctrl+S after making changes). And any CSS changes you make. You can essentially use your browser as a WYSIWYG/IDE.

Changing code on the fly after setting a breakpoint feels pretty magical. I do it a lot for projects.

Note: this gets less reliable if you're using React. VueJS seems to work fine for me though.

3

u/unkill_009 Jun 02 '21

Thanks man!

1

u/montrayjak Jun 02 '21

No problem!

0

u/Shinhan Jun 01 '21

F5 and everything is lost.

21

u/Strikerzzs Jun 01 '21

That's cool! But is it an experimental feature for Chrome Dev Tools?

36

u/i_got_dressed_today Jun 01 '21

No, all major browsers support it

9

u/[deleted] Jun 01 '21

It was available in IE4, according to the MDN Docs

2

u/Ph0X Jun 03 '21

It's really really old, Both Chrome and Firefox have had it since 1.0

It was actually useful back when the web was just pure html.

2

u/[deleted] Jun 01 '21

a web developer will just edit the content in inspect element no? maybe this is exciting for non technical people

3

u/ishtiaq156 Jun 01 '21

Agree. Although, this comes in handy for creating mockups for screenshots.

6

u/funknut Jun 01 '21

You ever have to implement a JavaScript based wysiwyg editor for basic text formatting on a content management platform? It's pretty simple, but this is even simpler.

6

u/[deleted] Jun 01 '21

that's a pretty contrived example, I think almost everyone uses an external library for WYSIWYG editors. I don't think this mode is supposed to be used for production anyway.

1

u/funknut Jun 02 '21

You're referring to what I'm referring to. I am referring to a JavaScript library, as well.

→ More replies (1)

5

u/SleepyHarry Jun 01 '21

Huge generalisation.

In short, no. This is useful for fucking around with copy on a live site. I've used it on several occasions where I want to mess with various thing and right click - inspect element - click a bunch to get the text part - click out - Close devtools is a laborious process once, let alone several times on a site.

I've also used it for more QA related things where the amount of text is variable and I wanna see if I can break it. Again, saves a load of clicks / labour.

1

u/[deleted] Jun 01 '21

i see what you mean about testing the length of text

4

u/JacksonDonaldson Jun 01 '21

i just felt it

1

u/bullsized Jun 01 '21

How do you insert emoticons?

3

u/ishtiaq156 Jun 01 '21

You mean emojis?

On Mac use:
Control + Command + Space
For Windows:
Win + . or Win + ;

2

u/nuby_4s Jun 01 '21

my ass has been googling emoji's and copy/pasting on desktop for far too long, just blew my pea sized mind

7

u/BehindTheMath Jun 01 '21 edited Jun 01 '21

Source:

https://twitter.com/sulco/status/1177559150563344384

Edit: For all those downvoting, the post title and GIF came straight from this tweet. Give credit where it's due.

1

u/sulcoff Jun 02 '21

+ in the original video there's music which adds to the entertainment value.

Goddamn thieves :/

4

u/sundios Jun 01 '21

Wow! This is very cool! Thanks for sharing

2

u/preetam52ch Jun 01 '21

Wow!!! That is so cool. Thanks for sharing ☺️☺️☺️

2

u/purpleovskoff Jun 01 '21

I know that feeling well because I'm experiencing it right now

2

u/mrStark3 Jun 01 '21

This is dope !!! You get the silver award

2

u/itesasecret Jun 01 '21

next try:

document.partyMode = "On"

2

u/elbojoloco Jun 01 '21

This is just like setting contentEditable to true on the body element isn't it?

2

u/iWritePythonLikeThis Jun 01 '21

My instructor had this and I never understood why a blinking cursor would appear on wherever on the page he clicked until now

2

u/SleepyHarry Jun 01 '21

Sub protip is to wrap this into a bookmark (create a bookmark then edit the URL to be javascript:<code here>) and stick it on your bookmark bar. Now you don't even need to open devtools and type it out. Literal seconds per month saved.

2

u/[deleted] Jun 02 '21

Are you freaking kidding me...been developing for 8 years never saw this

2

u/iamasuitama Jun 02 '21

When would you need this for webdev? I can see needing it for fake twitter screenshots, but webdev?

3

u/Curiousgreed Jun 02 '21

Plenty of reasons, in general I do it to test if the layout breaks with longer texts.

2

u/The_Ransum Jun 02 '21

Snzjxmdnxjsmzkznsnsnsnssnjxjxnwbxj WHAAAAAAAAT?!

4

u/BrickTopsPigs Jun 01 '21

What is this sorcery?!?

0

u/whitecrow_dragon Jun 01 '21

I stopped using Chrome after I noticed it was eating 8gb of memory :'(

8

u/ishtiaq156 Jun 01 '21

What’s nice about this is, it’s supported by all major browsers. Check it out here https://caniuse.com/?search=Designmode

1

u/notpikatchu Jun 01 '21

Another cool tool. Guess this is my lucky day

4

u/4TH4RV- Jun 01 '21

Wtfff how is this not popular. Thank you for showing this to me

33

u/[deleted] Jun 01 '21

Because it's not really useful. There are better tools to design a web page, and rarely will you need to change page text/css on the fly

2

u/notpikatchu Jun 01 '21

“There are better tools to design a web page”

Could you suggest some?

7

u/dons90 Jun 01 '21

Figma, Adobe XD, Sketch

10

u/clintsuniverse Jun 01 '21

Figma balls

1

u/Bopeternn Nov 12 '24

Is it possible to use this command on a mobile phone, e.g. Chrome?

1

u/[deleted] Jun 01 '21

OMG you mean the feeling i have right now??

1

u/vicjicama Jun 01 '21

Thanks for sharing, this is cool!

1

u/[deleted] Jun 01 '21

How am I just now seeing this???? It's awesome!

1

u/luzacapios Jun 01 '21

Dannnnngggg! 😎 magic! I see some interesting possibilities. I hope I remember this when an opportunity arises.

1

u/milosh-96 Jun 01 '21

Firefox (the latest version) supports this too!

1

u/dronzaya Jun 01 '21

What is this witchcraft!!??

1

u/pas43 Jun 01 '21

Can you edit positions and display modes?

1

u/nothankyouthankstho Jun 01 '21

Got excited. Showed partner. Deleted their Tumblr because I played with fire

1

u/[deleted] Jun 01 '21

My life is a lie.

1

u/[deleted] Jun 01 '21

does it do anything except turn the page into a big series of text fields? can you change the layout or anythign?

1

u/[deleted] Jun 01 '21

I just discovered document.designMode

1

u/Random_Aspirant Jun 01 '21

Excuse me , but wtf , and I'm learning about this now!!!

1

u/MarmotOnTheRocks Jun 01 '21

Uses:

99% for funny screenshots

1% for actual productivity

1

u/TankorSmash Jun 01 '21

If you see the autocomplete grey text, just hit tab, don't type it out if you don't have to.

1

u/coolgamer2354 Jun 01 '21

I need this.

1

u/dromance Jun 01 '21

wow . boss

1

u/[deleted] Jun 01 '21

What the actual fuck

1

u/tamilking7 Jun 01 '21

It's not works for me oh, am I missing something?

1

u/StupidWare Jun 01 '21

I'll give it a try.

1

u/turbotailz Jun 01 '21

How does this work with reactive libraries? Say I have a reactive title and the user is able to change that title using designMode, will the library react to the change or does this screw things up?

1

u/Sol3141 Jun 01 '21

I'm passed i haven't heard of this before now!

1

u/[deleted] Jun 01 '21

Bruh

1

u/[deleted] Jun 01 '21

“I was just reading your final edit — um, there seems to be an inordinate number of exclamation points.”

1

u/Redtitwhore Jun 02 '21

How we used to develop before the web...

1

u/samuelrir Jun 02 '21

This feature is compatible with Edge too? This is super productive

1

u/n34t-bot Jun 02 '21

That's it man

1

u/shellwe Jun 02 '21

How long has this been a thing?!?!?!?!?

1

u/jonesy346 Jun 02 '21

Bruh this is amazing this is literally the highlight of my week so far, thank you for this wonderful tip 😊❤️

1

u/Ok_Cantaloupe_1601 Jun 02 '21

I love that feeling. Which is now. I have that feeling now.

1

u/[deleted] Jun 02 '21

Woah

1

u/varrshith Jun 02 '21

DevTools getting better and better.

1

u/SampathKumarReddit Jun 02 '21

Wow wow, I can show my friends that I am on the internet right?.

1

u/Random_9492 Jun 02 '21

This is GOLD

1

u/ejilee Jun 02 '21

Whattt

1

u/karma_5 Jun 02 '21

This the most useful post(for me) i have ever found in reddit.

1

u/McDreads Jun 02 '21

Wow, I had no idea about this!

1

u/Samtos141 Jun 02 '21

Thanks for sharing, I need a web dev job btw,

1

u/Fit_Till_2594 Jun 02 '21

Cool trick, I just deleted the Twitter

1

u/LightReads Jun 02 '21

Looks good. Would you guys know of any other application/site that does similar? Thanks!

1

u/aat36 Jun 02 '21

Thank you good sir, you have probably changed my life. Hahaha.

1

u/Pirros_Panties Jun 02 '21

Well that’s a time saver

1

u/Zit-Bangla Jun 02 '21

That's awesome

1

u/HemetValleyMall1982 Jun 02 '21

For us, it is fantastic, but may have a dark side.

After compromising a user's computer, scammers have ways to use the DOM inspector to alter the way a mark's browser displays bank account information. This makes it much easier for the scammer. For more about this, see Kitboga's channel on YouTube.

1

u/therealangryturkey Jun 02 '21

I'm curious how a scammer benefits by showing me I have more or less money in my bank account. Maybe that's not what they do, but it is interesting.

1

u/HemetValleyMall1982 Jun 02 '21

Scammer calls 'customer' and informs them that Amazon or Microsoft has overbilled them $700, and they are eligible for a refund.

Somehow, scammer convinces customer to install a remote PC program. Scammer now has remote access to computer.

Scammer tells customer to log into their bank to see the $700 'refund'.

Customer logs into bank, scammer takes control of mouse and enters developer mode in browser, changes bank balance on-screen and/or inserts new divs into DOM to show 'transactions' on the bank account, with bank.com still in the address bar. Looks legit.

Scammer then requests customer to send the $700 back to them using a bank account transfer.

Customer is now out $700.

1

u/[deleted] Jun 02 '21

Whaaaat….?!

1

u/PointandStare Jun 02 '21

document.designMode="on"
Start editing.

1

u/its_dizzle Jun 02 '21

The only thing this is useful for (IMO) is making sure elements work with varying lengths of copy relatively quickly. Because, as we all know, clients will always add more copy than you expected.

1

u/viayensii Jun 02 '21

I remember doing this to prank my classmates in college. it's a shame that I forgot about this now that I have a job.

1

u/Hairy_Shine_6629 Jun 05 '21

OMG I just discovered it and it's awesome!

1

u/[deleted] Jun 11 '21

You only changed text Can you upload images?

1

u/[deleted] Jul 12 '21

I think I am lucky that I am very new in web development and found this.

1

u/SeeYouInForever Aug 20 '21

I thought one would be able to do a lot more with the document.designMode function. Although, still a pretty impressive discovery!

1

u/summonthejson Apr 09 '22

It is what hackers use ;)

1

u/SnowBoy1008 Jul 18 '22

I'm am so glad I decided to look at r/webdev

1

u/ConduciveMammal front-end Sep 02 '22 edited Sep 02 '22

Whilst it’s cool as hell, does it actually have any real use cases?

Edit: I just realised I commented on a 1.5 year old post 😑

1

u/Ampix0 Jun 02 '21 edited Jun 02 '21

Credit the twitter account this was stolen from. @sulco

Even the title is from the tweet

0

u/nftpedia Jun 01 '21

Is this magic?

0

u/gbjcantab Jun 01 '21

Lol that everyone’s amazed... I remember sitting with friends in middle-school home room in, what, the mid-2000s? And messing around with design mode.

0

u/crypt0isthefuture Jun 01 '21

/u/nano_tipper 5USD This is fucking awesome! You literally changed my life!