16

I've been having a look at Chrome extensions and I'd like to create an extension that interacts with a web page using a sidebar. So, user clicks button to launch extension, and the current page splits, with the right hand portion displaying my extension. I tried below, but I see nothing (working or otherwise). I'm not overly surprised it's not working as I do not have a sidebar.html file for one thing. The reason I have that in the manifest is because I saw it in another post in this site. The suggestion there was to use the "sidebar" line in manifest.json, but "sidebar" isn't even mentioned in the documentation as being a valid part of the manifest syntax.

manifest.json:

{
  "name": "Test 1",
  "version": "1.0",
  "description": "Test Extension 1",
  "page_action": {
    "default_icon": "icon.png",
    "default_title": "Testing",
    "default_popup": "popup.html"
   },
  "sidebar" : {},
  "permissions": [
    "experimental"
  ]
}

popup.html:

<script>
  chrome.experimental.sidebar.show();
  chrome.experimental.sidebar.expand();
  chrome.experimental.sidebar.navigate({path: "sidebar.html"});
</script>

I've enabled 'experimental'.

Thanks for any help.

2

2 Answers 2

33

The problem is that you are opening, theoretically, the sidebar inside your popup, not in the current page.

You should add a content script in the page, with a function that opens the sidebar. So, in your popup you should just retrieve the current tab then call this function from it.

Also, as Boris Smus said in your question, sidebars will be discontinued in future versions. So I advice you to create your own sidebar frame via content scripts.


Update

To help you, I've made a simple extension that create a sidebar on current page.

@Curtis hosted my sample extension on Github, you can clone it here.

5
  • Thank you. Trying to create a sidebar frame with content script as you suggest but I can't find any coherent documentation, just snippets everywhere, nothing tying the pieces together. In manifest.json, I put "content_scripts": ["js":["test_content_script.js"]}], so how does the script in there get invoked? Do I call a function in test_content_script from popup.html? Thanks.
    – user265330
    Sep 13, 2011 at 11:35
  • The sidebar is for a specific url? Sep 13, 2011 at 11:50
  • 1
    Thank you very much for taking the time to do that. I have downloaded it and it works beautifully. I will try to amend so that the sidebar does not hide part of the original page, but I am very grateful to you for getting me off the blocks! Thanks again.
    – user265330
    Sep 13, 2011 at 17:21
  • 1
    You're welcome! If it solve your problem, please vote up the answer and mark it as accepted! Sep 13, 2011 at 17:25
  • I marked it as accepted, but when I tried to vote up it told me I needed a reputation of at least 15.
    – user265330
    Sep 14, 2011 at 7:34
5

I was looking for a sidebar solution as well and ended up at Implement chrome.sidebar API thread.

According to the Sidebar PRD, it is already possible to create sidebar by:

  1. injecting a script into the page which edits the HTML of the page to display a sidebar by modifying the DOM to insert an iframe which loads the contents of the sidebar from a remote server.
  2. the injected script can edit the DOM directly to display a sidebar, the contents of which are passed via message.

However, there are many downsides (explained in the same document) with regard to:

Usability, Performance, Security, Privacy (Extension sniffing as well as Third party cookies) and Accessibility.

You can watch a demo of what they are preparing for future Sidebar Component.

It might help in shipping the feature quicker if you star the thread.

update

Per this comment, Chrome will not get a built-in sidebar component.

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Jul 30, 2015 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.