37

Google docs can “lock” a page so that it’s impossible to copy from its text. This seems wrong to me; shouldn't a computer’s ability to copy and paste be intrinsic? I can’t understand how a webpage can “overstep” its authority and prevent my computer from doing something totally natural. It seems that if I can be served and display text that I should be able to copy it.

How does this webpage prevent my machine from copying?

Mr_Dave
  • 547
  • 1
  • 8
  • 17
  • 2
    It's using a script to prevent you from copying the text. This is incredibly easy to bypass in Chrome by simply [disabling JavaScript by using the developer tools](http://stackoverflow.com/questions/13405383/how-to-disable-javascript-in-chrome-developer-tools). I've tested this myself just now, and it works fine - you can then copy and paste the text after disabling JavaScript. As to the exact details of the script that prevents copying, there are several ways that this could be happening, many of which can be found on this site, but I'm not sure exactly how Google Drive implements this. – Random Davis Oct 28 '16 at 02:07
  • 1
    Since your question is How they prevent copying, I can not put it as an answer. If someone wants to copy the text, scroll to bottom most area of page and then use browser console with this command `document.body.innerText`. For more accurate results - navigate to https ://docs.google.com/document/d/[ID]/preview – th3pirat3 Apr 23 '18 at 17:34
  • I used the Chrome distiller feature and copied the text from there -- worked for a doc, but not sure about spreadsheets. Though it did mess up the formatting a bit. – Keegan Mar 30 '19 at 02:43
  • Working solution in the middle of 2019: 1. replace last url part to /preview 2. goto chrome debugger find the table, copy it's content to clipboard 3. use services like http://www.convertcsv.com/html-table-to-csv.htm to convert html to xls/csv – pymen Jul 09 '19 at 08:16
  • 2
    As of 9/9/19, you can create an [achieve of the page](https://web.archive.org/) then print off the page as a PDF while having it still retain text. However, it breaks formatting after page 30 and bullet points get replaced with a "" – Mehvix Sep 09 '19 at 05:13
  • 1
    As of 2019-11-03 this javascript will copy the current document data into the blank document. Because the code is long, it is given in the next comment: – Jay Dadhania Nov 02 '19 at 22:25
  • 2
    `blankDocumentink='xxxxxxxxxxxx'; a='';for(s of document.body.getElementsByTagName('script')){if(s.innerText.indexOf('DOCS_modelChunk = ')===0){a+=s.innerText.replace('DOCS_modelChunkLoadStart = new Date().getTime(); _getTimingInstance().incrementTime(\'mp\', DOCS_modelChunkLoadStart - DOCS_modelChunkParseStart); DOCS_warmStartDocumentLoader.loadModelChunk(DOCS_modelChunk); DOCS_modelChunk = undefined;', 'DOCS_warmStartDocumentLoader.loadModelChunk(DOCS_modelChunk);');}}w=open(blankDocumentink);setTimeout(w.eval, 5000, a);` – Jay Dadhania Nov 02 '19 at 22:25
  • 1
    Usage: > Create a blank document in your google doc. > While in edit mode, copy its link. > Replace xxxxxxxxx with this link in the code above. > Now open the target google doc that is protected. > Hit F12 > Go to "Console" > paste the code there > Wait till it opens the blank document and copies data into it. > ****MOST IMPORTANT - DON'T EDIT/CLOSE YET**** > Hit Ctrl+A (Select All) - right click - Copy > Refresh (F5) > It will load the blank document again > Paste the data you just copied (Ctrl+V). > Now it should be saved automatically. (contd...) – Jay Dadhania Nov 02 '19 at 22:34
  • 1
    (...contd.) Alternatively, you can paste the data in MS Word or any such word processor. Also, please note that this code works for all page contents EXCEPT IMAGES. Images in the protected document will be displayed as blank boxes. – Jay Dadhania Nov 02 '19 at 22:36
  • 2020-09-12, working on a Macbook Air with Chrome 85.0.4183. 1. Replace /edit... in the URL with /preview 2. Open the Javascript Console 3. Run the following command in the console: copy($("iframe").contentDocument.body.innerText) 4. Paste into a target document – mcw Sep 12 '20 at 17:42
  • Kinda late, but my solution here still works for Google Docs: https://webapps.stackexchange.com/a/141493/244349 – idontknow Feb 06 '21 at 19:09

5 Answers5

76

Here is how to copy (or print) the protected google sheet values.

NOTE: With this technique you can copy the cells from each sheet; it's not possible to duplicate the spreadsheet file itself. Formatting is preserved but formulas are not.

  1. Change the URL to:

    https://docs.google.com/spreadsheets/u/1/d/***[document id]***/preview

    The document ID is the random string found in the google sheet URL that is normally 40 to 45 characters long.

  2. For each sheet, type Ctrl+A, Ctrl+C

  3. Paste the cells into another spreadsheet. Formatting

Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
Sachi
  • 1,286
  • 1
  • 10
  • 17
30

As of the 10th of May, 2018, disabling JavaScript will not load the document at all, and changing the 'edit' to 'preview' also no longer works.

I have found that if you click on the three dots and go to: More Tools > Developer Tools and then click on console, and type in 'document.body.innerText', it loads the entire document as a text file, so that you can copy to your heart's content.

Woodman
  • 1,502
  • 2
  • 12
  • 20
  • I just the the following returned in the console: ```" View only Windows To enable screen reader support, press ⌘+Option+Z To learn about keyboard shortcuts, press ⌘slash Sheet1 Explore Sum: 2758560 Anonymous Squirrel has joined the document."``` – AllanLRH Jun 23 '18 at 14:43
  • 2
    Well I'm sorry to say you must have done it wrong - as I just tried it again, in both macOS and Chrome, and it worked as I described. – Woodman Jun 24 '18 at 03:25
  • Weird, can you try it with [this Google spreadsheed](https://docs.google.com/spreadsheets/d/1FUWDGiVWe_JF7fxvJ_tWjpOkFzV98_kUIPucos1exJ8/edit#gid=0), which is protected from exporting and copying of it's contents? – AllanLRH Jun 24 '18 at 08:00
  • 2
    Sorry mate, spreadsheets are a whole different ball game. The original question was asking for a Google Doc, so that what my answer was for. You should create a new question for spreadsheets, hopefully someone knows! – Woodman Jun 24 '18 at 09:15
  • 1
    This should be marked as the current correct answer. – Petter Jul 09 '19 at 13:35
  • 7
    This doesn't work anymore. – Abhishek Sharma Jul 07 '20 at 18:14
10

Disable javascript in with developer tools, right click the page, click 'print', change the print destination from your printer to 'save as pdf', and you've got it.

user10401701
  • 101
  • 1
  • 2
3

EDIT: This doesn't work anymore

I've found out how they're disabling copying, so I'm turning my comment into an answer.

Here's the script that runs on the page that prevents copying:

function rtcScript() {
    document.oncontextmenu = null;
    document.onselectstart = null;
    document.onmousedown = null;
    document.onclick = null;
    document.oncopy = null;
    document.oncut = null;
    var elements = document.getElementsByTagName('*');
    for (var i = 0; i < elements.length; i++) {
        elements[i].oncontextmenu = null;
        elements[i].onselectstart = null;
        elements[i].onmousedown = null;
        elements[i].oncopy = null;
        elements[i].oncut = null;
    }
    function preventShareThis() {
        document.getSelection = window.getSelection = function() {
            return {isCollapsed: true};
        }
    }
    var scripts = document.getElementsByTagName('script');
    for (var i = 0; i < scripts.length; i++) {
        if (scripts[i].src.indexOf('w.sharethis.com') > -1) {
            preventShareThis();
        }
    }
    if (typeof Tynt != 'undefined') {
        Tynt = null;
    }
}
rtcScript();
setInterval(rtcScript, 2000);

Notice that it's setting every element to not be copyable, selectable, or cuttable, as well as disabling the context menus. This is trivial to bypass by disabling scripts on the page. See this question for how to do it on Chrome. I've tested this myself - if you disable JavaScript via that method while viewing the locked document, you can immediately begin selecting and copying the text with no issues.

Random Davis
  • 6,662
  • 4
  • 14
  • 24
3

I tried the other options and none worked for me - then, tried downloading webpage and saving link. Re-opened from docs, and then I was able to download as PDF.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253