Is it possible to "manually" open your Facebook messages, "programmatically"? - javascript

Is it possible to "manually" open your Facebook message inbox in-browser, programmatically?
(i.e., via the "native" code/functions that Facebook normally uses to do it -- without using Facebook's API, and without an actual mouse click or Tab-Enter of the icon)
On Facebook, when you put the mouse over your message-inbox icon and click -- the inbox drops down.
Would it possible to capture programmatically what's actually happening when this is clicked, thus making the inbox drop down as if the icon had been clicked (like a debugger catching function calls)?
And if so, would it be possible to manually "replay" this programmatic pull of the puppet-strings that a mouse-click would pull, to emulate this click and see the ensuing drop-down of the inbox, -- again without using the API or any kind of physical or automated clicking/tab-entering?
This doesn't necessarily have to be done through an entirely self-contained program. If it's possible to do in-browser, like via Javascript (Scratchpad)/Greasemonkey (sans FB API) -- all the better.

You probably can't do this with PHP.
Your best bet would be to use a browser automation tool that will record your actions and play them back. For example, but not necessarily, Selenium.
This will simulate the manual clicking of elements on the page, without using the Facebook API.

Related

Web extension - alternative to notification with button

I have a web extension that lets any website access the clipboard. On request I will ask the user if it is okay to give access to the clipboard.
I do this in two ways
I create a notification
The problem: firefox doesn't allow buttons, so in the message I say "Click here to allow website x access". I added an eventlistener to the notification that sends a message back to the content script and it proceeds from there. It's okay but not really the best solution (I want buttons)
As a fallback I have a simple confirm box.
The problem: it doesn't really look good.
Now my other idea is to create a custom confirm box. That means create some html, css and javascript and append it to the DOM. This although is potentionally dangerous as websites can just trigger a "click" on the "allow access"-button then.
So I am basically looking for a nice and safe way to get confirmation from the user.
So what next? iframes? Is it possible to include an html page from the addon with access to a content script in an iframe?
Or is there some other way I can implement this maybe web extensions already offer something like this?
Completely overlooked the click event argument. There is a event.isTrusted property which is false when the event was triggered. (maybe not available in all browsers). But this pretty much solves the issue.

Opening a webpage and automatically calling an OnClick function

We have a small group of guys who play the game below. We take these games and stream them on Twitch so we can watch them as a group live. We have gotten down the process of automatically opening the URL and streaming the games. However, to get the plays to show there is an OnClick function that we have to manually remote in each time and click. Is there a way we can open this webpage and simulate the click so they are turned on? If you click the link below, you'll see a yellow button called Plays. If you click it you'll see what we want to be able to turn on without manually having to do it.
http://glb2.warriorgeneral.com/game/replay/171542
This depends a lot on how you're automating the page opening.
Normally, you can simply call .click() on an element in JS. But since you want to click something on a page you don't control, it gets complicated.
If you're simply opening a new tab/window via Javascript, you won't be normally able to do this because of cross-domain JS protections. You can disable them which is not recommended--if you go this path, you'll want to load the page in an iframe and execute a callback on it: see this answer. The callback you'll want will look something like:
function(){ window.frames[0].document.getElementById('toggle_plays').click(); }
Knowing how you're doing the automation would help significantly on how to solve the problem within your limits.

How to trigger a click event of a button with javascript on an arbitrary site

I need to navigate through a particular website, frequently, to get at some sub-page that is several layers beyond the front page and it is taking too much time to click and scroll and click and scroll to get at the desired final screen where I enter the search string. So, I would like to automate the process by making Javascript trigger the right button events to get me to the distant page where I can enter the search string manually.
So, I know how the code needed to trigger the event,
document.getElementById('x').click();
but how can I implement this inside my browser, since this is not my own website?
If this is going thru different pages, then probably a Web UI automation tool would be the best (like Selenium - http://www.seleniumhq.org).
as #elcarns says, if you need to inject code into another's website, you could do so opening the console (view --> developers --> javascript console in Chrome).
Another, more complex way to do it when you have to traverse several pages is by developing a plugin.
javascript:document.getElementById('x').click(); in the url bar. You can probably make a bookmarklet for it as well.

Tracking Social Button Clicks in Javascript

On a website, I have some social buttons (tweet, facebook like, google+1, ..). Most of them are inserted using an iframe.
The task is to track use interaction with those buttons: if someone +1'ed the content - and AJAX request should update my local statistics on the server.
However, with JS I can't access the contents of the iframe due to security restrictions: can't bind 'click' event.
How do I track clicks on those social buttons, then?
Possible solutions:
Bind 'click' to the iframe object itself: it does not work.
Add buttons inline, w/o an iframe. No go: I should also display the number of likes for every button.
Try to use Social Service APIs to insert without an iframe. Not all services support this.
You can't. If you could catch clicks on them you could also trigger clicks on them which would be pretty bad (imagine porn sites making you "like" them automatically).
The only thing you can do is using the APIs of the various sites to retrieve the number of people who liked/+1'd/etc. your site.
Most of the social buttons from the main companies enable your Javascript to detect when the button has been pressed. They usually do this via Javascript events.
In other words, they'll tell your code that they've been pressed, you don't have to detect it on your own.
Twitter
info on their javascript events
Facebook
You need to use the XFBML version of the button. From the Facebook Like button FAQ
How do I know when a user clicks a Like button?
If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.
Google +1
See the callback parameter in their docs. See section +1 Tag Attributes. You provide a Javascript (JS) function to their button. Your JS is then called by them when the button is pushed. Easy!

Is there a way to __doPostBack to another page using javascript?

I'm writing a suite of admin tools to sit on top of our existing site that will allow a user to quickly administer a number of pages from one convenient jquery ui window.
The issue I'm running into is that a lot of the functionality requires postbacks on specific pages, while this admin overlay can be accessed from any page. This means that in order for the functionality to work, the postback has to be sent to the correct page (or the page has to be loaded before the postback is triggered).
I've looked at Causing a PostBack to a different page from a PopUp and several c# posts, but they do not appear to address the specific issue of moving to another page prior to firing the postback using javascript.
Possible Solution: one solution I considered is using cookies transmit information about which postback events need to fire and what parameters to use while using javascript to load the correct page. It's not a great solution, so I was wondering if anyone here could think of a better one.

Categories