Is there a way to re-enable execCommand in Chrome 6

317 views
Skip to first unread message

Jamie

unread,
Sep 7, 2010, 8:18:26 AM9/7/10
to Chromium-extensions
I have an extension that relies on execCommand for auto copying
selected text. It appears that execCommand is no longer working in
Chrome 6.0.472.53. From what I've found it sounds like this
functionality may have been disabled in WebKit (http://code.google.com/
p/chromium/issues/detail?id=43206). I also came across this (http://
groups.google.com/a/chromium.org/group/chromium-extensions/
browse_thread/thread/6e25eeea7cd3bdce/5bce381196e75696?
lnk=gst&q=execCommand#5bce381196e75696) discussion where it is stated
that copy would not be disabled in extensions. In the same thread
someone stated, "it should be re-enabled with a 'clipboard' manifest
permission in the future." I haven't been able to find anything else
on the "clipboard" manifest. Also, I see there is an experimental
clipboard API, but the work to enable experimental features for end
users is onerous.

I'm trying to figure out if there is a way to re-enable execCommand
for extensions in Chrome 6 so that I can fix mine. Does anyone have
an advice or ideas?

Thanks.

Bazinga

unread,
Sep 7, 2010, 10:23:14 AM9/7/10
to Chromium-extensions
Well, looks like what you heard was true. The execCommand does work in
extensions. I'm running Chrome 7 now, and even when I ran 6, my
extension which too relied on the execCommand for copying worked
flawlessly. So, make sure you haven't changed your code since it was
working last. It works in the extension, but not on a normal page.

PhistucK

unread,
Sep 7, 2010, 10:55:54 AM9/7/10
to Bazinga, Chromium-extensions
Note that it means that it will not work within content scripts.

The clipboard API is an experimental API, which means it is currently only available in Dev releases\Canary\Chromium builds and needs a command line flag in order to work.


PhistucK



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Jamie

unread,
Sep 10, 2010, 10:13:30 AM9/10/10
to Chromium-extensions
Follow up: I found that execCommand("copy") is returning false inside
the content script. However, it is returning true if executed in the
background page. Executing it in the background page however would
not copy the selected text on the active web page. I'm guessing on
this, but I think this failed because the context for execCommand
changed to the background page, and not the active HTML page. Since
there was no selection on the background page nothing got copied. I
did figure out that I can take the selected text from the active HTML
page; put it into a textarea on the background page; select the
contents; and execute execCommand("copy") that this will copy the text
to the clipboard. However it has the side effect that all formatting
is lost. Copying with or without formatting was an option in my
extension, but for now I'm forcing the behavior in order to get
something working.

I hadn't modified my extension since 2/10 so I'm confident this is a
change in behavior with Chrome 6. Does anyone know if this is
expected, or if I should file a bug report?

Thanks.

PhistucK

unread,
Sep 10, 2010, 10:48:40 AM9/10/10
to Jamie, Chromium-extensions
I remember reading that this was an intentional change.

PhistucK



Adam

unread,
Sep 10, 2010, 10:55:28 AM9/10/10
to Chromium-extensions
I've developed an extension with similar functionality. I've had to
rely on chrome.experimental.clipboard.executeCopy(tab.id, callback)

Documentation here: http://code.google.com/chrome/extensions/dev/experimental.clipboard.html

Whatever text is highlighted in the tab specified will be copied. The
Content Script has to send a message to the background page, and then
the background page can execute the copy in the specified tab. The
downside is that this feature is experimental and requires
experimental permissions.

Perhaps someone with more knowledge than I could let us know about any
plans to ditch chrome.experimental.clipboard or to migrate into the
stable APIs.

-Adam

Aaron Boodman

unread,
Sep 10, 2010, 7:46:02 PM9/10/10
to Adam, Chromium-extensions
Content scripts -- that explains it. We meant to not regress this
functionality, but we only did it for extension pages not content
scripts.

I've opened a new bug: http://code.google.com/p/chromium/issues/detail?id=55188

I'm not sure what we'll be able to do for Chrome 6, but you can star
that to stay informed.

- a

Reply all
Reply to author
Forward
0 new messages