Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 8 of 8

This is a discussion on Page Action development problems :x within the Plugins Development section, part of the Chrome Plugins category: Ok so I'm trying a simple "Share On Facebook" page action... It's global, for any page, and clicking it should ...


  1. #1
    henasraf's Avatar
    henasraf is offline Junior Member
    Join Date
    Aug 2009
    Posts
    3

    Default Page Action development problems :x

    Ok so I'm trying a simple "Share On Facebook" page action... It's global, for any page, and clicking it should show the sharer window. Simple right? Well it's not working... The action just won't show up. What do I do? Here are the files:
    manifest.json
    Code:
    {
    	"name": "Share On Facebook",
    	"version": "1.0",
    	"description": "Share the current page with Facebook Share.",
    	"background_page": "background.html",
    	"page_actions": [
    		{
    			"id": "facebookshare",
    			"name": "Share this page on Facebook",
    			"icons": ["facebook.png"]
    		}
    	],
    	"content_scripts": [
    		{
    			"matches": ["http://*/*"],
    			"js": ["share.js"]
    		}
    	]
    }
    background.html
    Code:
    <html>
    <head>
    <script type="text/javascript">
    	chrome.pageActions.enableForTab(
    		"facebookshare",
    		{
    			tabId: -1,
    			url: document.location.href
    		}
    	);
    </script>
    </head>
    </html>
    share.js
    Code:
    function ShareOnFacebook()
    {
    	var d=document,
    		f='http://www.facebook.com/share',
    		l=d.location,e=encodeURIComponent,
    		p='.php?src=bm&v=4&i=1230248675&u='+e(l.href)+'&t='+e(d.title);
    		1;
    		try {
    			if (!/^(.*\.)?facebook\.[^.]*$/.test(l.host))
    				throw(0);
    			share_internal_bookmarklet(p)
    		}
    		catch(z) {
    			a=function() {
    				if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436,location=0'))l.href=f+p
    			};
    			if (/Firefox/.test(navigator.userAgent))
    				setTimeout(a,0);
    			else {
    				a()
    			}
    		}
    	void(0);
    }
    I'm probably doing a million things wrong... But what are they? D:
    I'll bet I'm getting the tab ID wrong, I saw -1 in the RSS reader example extension, but I think they had a function to decide the tab ID or something... How do I just enable it for all tabs?
    Last edited by henasraf; 08-07-2009 at 12:47 PM.

  2. #2
    nemrod's Avatar
    nemrod is offline Member
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    34

    Default

    You can use the Chrome tabs API to get the ID (and actually the URL as well, instead of document.location.href).

    Code:
    chrome.tabs.getSelected(null, function(tab) {
    	chrome.pageActions.enableForTab(
    		"facebookshare",
    		{
    			tabId: tab.id,
    			url: tab.url
    		}
    	);
    });
    This should do it. Experiment with it

    http://dev.chromium.org/developers/d...sions/tabs-api

    edit: looking closer at your code, you're not even listening for the page action?
    I haven't used page actions before, but if I were you I'd try putting the code above in share.js and moving the function to the background script. Then I'd create a listener in the background script that looks something like this:
    Code:
    chrome.pageActions["facebookshare"].addListener(function(paId, tabId, tabUrl) {
    	ShareOnFacebook(tabUrl);
    });
    And make the URL an argument to the ShareOnFacebook function. Either that or you can just put the code from the function inside the listener, won't really change anything just make the code smaller.

    But yeah, just what I'd do. Never used 'em before so I don't know if I'm doing it the right way.
    Last edited by nemrod; 08-09-2009 at 08:56 PM.

  3. #3
    henasraf's Avatar
    henasraf is offline Junior Member
    Join Date
    Aug 2009
    Posts
    3

    Default

    Tried that, but still no good :x inspector says,
    Uncaught TypeError: Cannot call method 'addListener' of undefined

  4. #4
    nemrod's Avatar
    nemrod is offline Member
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    34

    Default

    Quote Originally Posted by henasraf View Post
    Tried that, but still no good :x inspector says,
    I'm gonna try and get an example running to see if I can make it work.

    edit: I've got the page action being activated and everything no problem, but my listener isn't doing anything. I'm not getting an exception, which means it's working I guess, but none of the code in the listener seems to be executed. :S

    edit2:
    manifest.json
    Code:
    {
    	"name": "Page Action Test",
    	"version": "1.0",
    	"description": "Testing Page Actions.",
    	"background_page": "background.html",
    	"page_actions": [{
    		"id": "myaction",
    		"name": "Page Action",
    		"icons": ["favicon.ico"]
    	}]
    }
    background.html
    Code:
    <script type='text/javascript'>
    chrome.tabs.onUpdated.addListener(function(tabId, chprops) {
    	chrome.tabs.getSelected(null, function(tab) {
    		chrome.pageActions.enableForTab("myaction", {
    			tabId: tab.id,
    			url: tab.url,
    			title: tab.url,
    			iconId: 0
    		});
    	});
    });
    chrome.pageActions["myaction"].addListener(function(details) {
    	var tabId = details.data.tabId;
    	var tabUrl = details.data.tabUrl;
    	chrome.tabs.get(tabId, function(tab) {
    		chrome.tabs.create({url:tabUrl,index:tab.index+1});
    	});
    });
    </script>
    With this code I get the page action for all tabs no problem. Still, the tab that's supposed to be created isn't (I've tried having the code in a toolstrip, having parts of it in one and parts in the other, tried all kinds of stuff but no matter what the code in the listener doesn't seem to be executing). This is really confusing because it really should work. What's going on? Is the API not fully implemented? Am I making some newby mistake?
    Last edited by nemrod; 08-11-2009 at 05:48 AM.

  5. #5
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    Might be a bug in Chrome...I just tried the RSS sample and its not opening the subscribe page which Im sure its meant to (never used it before).
    http://dev.chromium.org/developers/d...nsions/samples

  6. #6
    nemrod's Avatar
    nemrod is offline Member
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    34

    Default

    Quote Originally Posted by PAEz View Post
    Might be a bug in Chrome...I just tried the RSS sample and its not opening the subscribe page which Im sure its meant to (never used it before).
    http://dev.chromium.org/developers/d...nsions/samples
    You're right. The page action API must've become broken during an update. :/
    I'm gonna check to see if anyone has reported it

    edit:
    http://code.google.com/p/chromium/is...etail?id=18240
    Last edited by nemrod; 08-11-2009 at 06:50 AM.

  7. #7
    henasraf's Avatar
    henasraf is offline Junior Member
    Join Date
    Aug 2009
    Posts
    3

    Default

    They say the bug's fixed now, do I have to wait for an update of Chrome for it to work? D:

  8. #8
    nemrod's Avatar
    nemrod is offline Member
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    34

    Default

    Quote Originally Posted by henasraf View Post
    They say the bug's fixed now, do I have to wait for an update of Chrome for it to work? D:
    Yeah, unless you use SVN I guess.
    I saw it a couple of days ago and have been waiting for an update since, taking quite long

Similar Threads

  1. Google Bookmarks Page Action
    By Wossname in forum Chrome Plugins
    Replies: 6
    Last Post: 08-11-2009, 10:18 PM
  2. Subscribe as a page action
    By rock_galore in forum Chrome Plugins
    Replies: 19
    Last Post: 06-23-2009, 04:27 PM
  3. Replies: 0
    Last Post: 06-18-2009, 06:11 PM
  4. Replies: 1
    Last Post: 03-14-2009, 02:49 AM
  5. Page loading problems...please help...
    By walking101 in forum Bugs and Vulnerabilities
    Replies: 0
    Last Post: 01-21-2009, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •