Calling Javascript within AppleScript to logout of Facebook Missing Value - javascript

I'm writing an Applescript utility to login to Facebook, do some simple tasks and then logout. I have everything working except logging out. I want to use Safari and most reliable method recommended has been to call Javascript versus using System Events. I'm open to either way as long as I can log out the user. The logout action is a menulist item which I attempt to locate, however I get "missing value" using this code. You help is greatly appreciated!
tell application "Safari"
if not (exists document 1) then reopen
tell document 1
set URL to "https://www.facebook.com"
delay 3
do JavaScript "document.getElementById('email').value='email-address';
document.getElementById('pass').value='password-value';
document.getElementById('loginbutton').click();
document.getElementById('persist_box').value='0';"
end tell
-- working code --
-- working code
-- Need to logout of this account
tell document 1
set URL to "https://www.facebook.com/logout.php"
delay 3
do JavaScript "document.getElementById('logout_form').childNodes[0].click();"
end tell
end tell
-- from the Facebook page View Code
-- role="menuitem"><form id="logout_form" method="post" action="https://www.facebook.com/logout.php"
onsubmit="return

Found help elsewhere. This worked!
tell application "Safari"
tell document 1
do JavaScript "document.getElementById('logout_form').submit()"
end tell
end tell

Related

Quickbase usertoken to supersede current user credentials/permissions

I have a custom button which is to query and possibly update an Administration App in Quickbase, which the current user doesn't require access to.
I have JS code which is executed on a button click by the user to check the admin app, etc...
my API call to check the app has the appropriate apptoken and usertoken. However, the browser still has the current user's session cached, so the API call errors out with an access denied error message.
I'm looking for either a way to make a hidden incognito window, to then execute this code, or a way to problematically force the usertoken to supersede the current user access/permissions.
I've seen where chrome extensions can use chrome.windows.create... but I have no experience with extensions, and Ideally, I don't want to have to have an extension for just this functionality, and have to possibly install it on every user's PC for this to work...
Here is a snippet of my current code... This code does work if someone has permissions to the Administration App... but this code is residing in a different application:
PreProcURL = "https://<domain>.quickbase.com/db/<dbid>?a=API_DoQuery&apptoken=<>&usertoken=<>&query={'3'.EX.'1'}";
PreProcQuery.open('GET', PreProcURL, 'async');
PreProcQuery.send();
PreProcQuery.onload = function(){
console.log(PreProcQuery.responseXML);
RunBit = (PreProcQuery.responseXML.documentElement.getElementsByTagName("runbit"))[0].innerHTML;
SupportData = (PreProcQuery.responseXML.documentElement.getElementsByTagName("supportdata"))[0].innerHTML;
if(RunBit != "1"){
$.get("https://<domain>.quickbase.com/db/<dbid>?a=API_EditRecord&rid=1&_fid_6=1&_fid_7="+rid+"&apptoken=<>&usertoken=<>");
}else{
if(SupportData == rid){
alert("This PreProc File is already in progress... please wait.");
}else{
alert("Another PreProc is already in progress... please wait.");
}
}
};
Thanks in advance for any assistance on this.
API calls executed in JavaScript that is hosted within quickbase.com (button, pages, etc.) will run as that logged in user that triggered the script. The usertoken gets ignored.
The most common way to accomplish what you are after is to write the API_DoQuery code on a server side location and then trigger it from your JS code.

How to disable or enable os services from html soft button

I have a page with html , so in my case i would to have a softkey button or slider which can function as ON & OFF ( in Single button ) main function for this button is to disable my WwanSvc whenever it is slided to OFF and to enable WwanSvc whenever i slide back to ON , so i'm looking for a help here that someone could provide good example.
Seriously i dont know anything about this since i'm a technical guy
#echo off
sc query "WwanSvc" | find "RUNNING"
IF %ERRORLEVEL% == 0 GOTO DISABLE
sc start "WwanSvc"
msg %username% DiGi Connected
TIMEOUT 1
EXIT
:DISABLE
sc stop "WwanSvc"
msg %username% DiGi Disconnected
TIMEOUT 1
EXI
This codes i'm using for a batch file but since a batch file cant show the state so i'm looking for a change to slider which can show ON or OFF
JavaScript is client-side only language and cannot affect the system it runs on for security reasons.
Normally one would write a daemon/service in a server-side language and your Javascript app will send commands to that service which has access to affect the system.

Cannot retrieve previously saved data from LMS - SCORM 2004

I'm trying to retrieve previously saved data from Moodle LMS but seems like something is not working. This is what I'm doing:
I load the SCORM (v2004) package into Moodle and perform some actions (like save navigation data or set completion status):
// Completion status always "unknown" at first time so I try to change it to incomplete:
API_1484_11.SetValue('cmi.completion_status', 'incomplete'); // "true"
...
API_1484_11.SetValue('cmi.location', '{"page":2}'); // "true"
Then later on commit these changes:
API_1484_11.Commit(''); // true
Request/Response:
When I leave and reenter the activity and try to retrieve this data again the API returns an empty string or the default initial value.
// I've already initialized the API at this point.
API_1484_11.GetValue('cmi.completion_status'); // "unknown"
...
API_1484_11.GetValue('cmi.location'); // ""
Am I missing something?
Do I need to call any other method to retrieve data from the server or something like that?
Or maybe I misunderstood the purpose of those methods?
I would appreciate any help on this topic. Thanks in advance.
Commit is important. Make sure you are setting cmi.exit to "suspend". SCORM 2004 in moodle isn't probably full featured unless someone finished it. Last I heard the Dev working on it gave up. So you may be dealing with a SCORM 1.2 implementation. I'm on a mobile device so I hope that gives you enough hints to troubleshoot. Good luck.

Pinterest API - Timeout

Has anyone experienced the "Trying to login before initializing." error?
It seems like there is a limit to the number of calls you can make to the API but I have not hit the 1000 per hour by any means.
This even occurs after I authenticate once. Once I refresh the page, I get the message above. I end up waiting a little bit (usually a few mins) then I can authenticate again.
I would like this to go away or at least save the authentication within a cookie or something like that.
Can anyone lead me in the right direction?
Appreciate the help in advance.
I was getting that same error message when setting appId to null or undefined in PDK.init. Maybe you are doing the init logic before the actual value is assigned.
I'd recommend using environment variables to keep the App ID outside of your code and inject it at build time, similar to how Create React App does it: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

rspec testing: putting :js => true also affects the before block

I have a page that is for booking an appointment and it has some javascript code that selects the earliest time and day when the appointment is available, after which user can click on the button to schedule the appointment.
So in order to test that, I was writing some rspec test like the following,
book_appointment_spec.rb
context "when on the profile page" do
before do
click_linkedin_button
end
it 'book an appointment', :js => true do
click_link "new-appointment"
choose "doctor1"
click_button "Submit and Schedule"
expect(page).to have_content "Congrats!"
end
end
click_linkedin_button is a method definition that just logins a user via linkedin oauth. The problem is that even after setting OmniAuth.config.mock_auth[:linkedin], whenever I set :js => true around it block, it asks me to login via linkedin, http://imgur.com/mYUOxgD
I was wondering if anyone knows how to fix this problem.
Following are other files that might be relevant to this problem.
spec_helper.rb
require 'capybara/webkit/matchers'
Capybara.javascript_driver = :webkit
Gemfile
gem 'capybara-webkit'
gem 'database_cleaner'
gem 'capybara'
As you've discoverd, you can't run part of a test using one driver and part of the test using another. This would be equivalent to saying
Given I login in using Safari.
Then I should be logged in using Firefox.
So your solution is that you have to run your js login code in the test environment to login. This is actually a good thing (you want to test your js login code). If you want to avoid actually connecting to linkedin, every time you run this test, then you need to mock the connection to linkedin. Have a look at VCR (https://github.com/vcr/vcr), this will allow you to record your connection to linkedin, so that in subsequent test runs you don't have to goto linkedin.
Setting js: true in your rspec block is a shortcut to use the javascript-enabled driver for the whole example. So this driver will be available and used during the whole execution or the example, which includes all before/after/around blocks.
To work around this, instead of using js: true, you can manually set which driver to use at the point(s) of your example where you need to.
it {
do_some_stuff_with_default_driver
Capybara.current_driver = :webkit
do_some_stuff_with_webkit
Capybara.current_driver = :selenium
do_some_stuff_with_selenium
}
EDIT
Oops I just read this, so perhaps that solution will not be working. please let me know
Note: switching the driver creates a new session, so you may not be able to switch in the middle of a test.
I solved it by creating an actual linkedin account, put that auth info in the .env and just called fill_in method to fill out email and password field during its callback. And stuck with running a js driver throughout the entire context block.
EDIT: This is of course not the best answer so I am still accepting other answers.

Categories