Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:11:26+00:00 2026-05-28T17:11:26+00:00

I’m writing a Chrome userscript to locally auto-save content in a CKEditor . I’m

  • 0

I’m writing a Chrome userscript to locally auto-save content in a CKEditor. I’m using this CKEditor auto-save plugin as inspiration.

I have written a function that fires every half second (via an interval) to register the CKEditor event handler:

var intervalId = window.setInterval(function() {
    if (CKEDITOR) {
        window.clearInterval(intervalId);
        CKEDITOR.plugins.add("user-script-auto-save", {
            init : function(editor) {
                editor.on('key', startTimer);
            }
        });
    }
}, 500);

However, it never properly completes, and complains that “CKEDITOR is undefined” on the if (CKEDITOR) statement.

Meanwhile, if I drop into Chrome’s console and type CKEDITOR, the console prints out the expected object.

What am I missing? The editor is embedded within an iframe; might that have an impact on scoping? Or am I fighting against Chrome’s sandboxing here? And if so, is there some other way I can dig into CKEditor to pull out the content every second or something to do the auto-saves?

I have not yet tried the script in Firefox; that’s next on my list.

Worth noting: I’m a long-time JavaScript novice. So I could easily be doing something dumb with scoping or something like that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:11:27+00:00Added an answer on May 28, 2026 at 5:11 pm

    According to this little tutorial video on YouTube, all the 3 “devices” are separated from each other in order to prevent XSS attacks from the user script to the browser / website and vice versa. Although the user scripts / content scripts are running in the website’s context, they are still kept separated from the actual website script context. You can easily acknowledge this by simply trying to access for example jQuery from a content script. Just as the CKEditor, it will not be available.

    So what I’ve come up with in order to deal with this is using the content script to include external JavaScripts in the head tag. AFAIK, this is not possible for files directly in the extension’s root directory, so I’ve taken a remote server to host my files.

    I’m not sure if this is the best approach and I think it is an ugly bypass, possibly way to powerfull and disabled by the Chromium Project some time.


    (Edited by OP, so I can select this answer and route karma appropriately)

    This answer, combined with some of the suggestions and links in the comments, ended up getting me to where I needed to be.

    I ended up with the following function:

    var insertScriptIntoDocument = function(scriptUrl, doc) {
        // inspired by http://blog.afterthedeadline.com/2010/05/14/how-to-jump-through-hoops-and-make-a-chrome-extension/
        var scriptText = doc.createTextNode(
            '(function(loc) {                                                    \
        var embeddedScript = document.createElement("script");                   \
        embeddedScript.type = "text/javascript";                                 \
        embeddedScript.src = loc;                                                \
        document.getElementsByTagName("head")[0].appendChild(embeddedScript);    \
    })("' + scriptUrl + '");');
    
        var injectorElement = doc.createElement('script');
        injectorElement.appendChild(scriptText);
        doc.body.appendChild(injectorElement);
    };
    

    Usage looks like so:

    var embeddedScriptUrl = chrome.extension.getURL("embedded-script.js");
    insertScriptIntoDocument(embeddedScriptUrl, document);

    For now, I’m executing this from within a Chrome extension, but I suspect that the pattern might work in a GreaseMonkey script deployed via the Chrome TamperMonkey extension provided that the URL of the script to be embedded was hosted somewhere reachable.

    FTR, as it turns out, I did not actually need to get to the iframe — the CKEDITOR variable was defined in the top-level document, but was simply not visible because of the rules of the Chrome sandbox

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.