Issues with logging in using Facebook Javascript SDK on Chrome and Safari (webkit) - Unauthorized Javascript intervention

I have encountered a problem that seems to defy the solutions proposed for similar questions on other platforms.

My local development site is hosted on a virtual machine at:

Upon loading the index.php page, I have a specific javascript code running (with the correct appId):

/* facebook auth */ 
window.fbAsyncInit = function() {
    FB.init({
        appId: '01234567890',
        channelUrl: 'http://lamp.site/channel.html'
    });
};

// Load the SDK Asynchronously
(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
}(document));

Subsequently, when a button is clicked, a particular javascript function is triggered:

#HTML
<li><a class="btn" href="#" ng-click="connectToFacebook()">Connect with Facebook</a></li>

#Snippet in AngularJS Controller
$scope.connectToFacebook = function() {
    facebookConnect.authenticate(
    function(reason) { // fail
        console.log(reason);
    }, 
    function(user) { // success
        console.log('logged in',user);
        //Session.login();
    });

    return false;
}

#Factory in AngularJS module
.factory('facebookConnect', function() {
return {
    authenticate: function(fail, success) {
        FB.login(function(response) {
            console.log(response);
            if (response.authResponse) {
                FB.api('/me', success);
            } else {
                fail('User cancelled login or did not fully authorize.');
            }
        });
    }
}

The Facebook authentication process works seamlessly in Firefox when I click the button. However, using Chrome or Safari on my PC, as well as Safari Mobile on my iPhone, triggers an error message and displays certain console data:

Unsafe JavaScript attempt to access frame with URL
https://www.facebook.com/dialog/permissions.request from frame with URL
http://lamp.site/index.php?page=login. Domains, protocols and ports must match.

Object
authResponse: null
status: "not_authorized"
__proto__: Object

User cancelled login or did not fully authorize. 

Although my testing URL is added correctly in the developer section of the Facebook app, it only works in Firefox. The channels file associated with this setup can be accessed at:

<script src="http://connect.facebook.net/en_US/all.js"></script>

I have experimented with including and excluding http: in the src= tag within the channel file, but the issue persists.

The settings for the Facebook app are as follows:

  • App domains: lamp.site
  • Site URL:
  • Mobile site URL:

Given its successful operation in Firefox, I am perplexed by the errors occurring in other browsers. Enabling cross-site scripting is not a viable solution, particularly for a mobile site. Has anyone recently resolved this issue? All related inquiries remain unanswered...

EDIT: To simplify matters, I have set up a new app ID on my website.

A screenshot displaying the app ID obtained from the Facebook Dev application panel can be found above.

Feel free to examine the source code, which has been directly copied from here:

https://developers.facebook.com/docs/guides/web/

The required channel file does exist:

Despite these efforts to streamline the process, I am still plagued by the recurring "An error occurred. Please try again later." message, albeit now redirecting to Facebook without authenticating and closing.

Edit: Upon adding the necessary site URLs, the simplified example now functions as intended.

Since the live site operates smoothly, the issue likely pertains to my local domains. An entry in my /etc/hosts/ file specifies the IP address of the VirtualBox Ubuntu server running on my laptop as:

192.168.0.13 lamp.site

This ensures seamless browsing of the site.

Answer №1

In order for it to function properly in Chrome, Sandbox Mode needs to be disabled. Surprisingly simple, yet effective.

I had originally turned on Sandbox Mode thinking it would prevent the content from appearing in search results, which was not my intention. Since it was working fine in Firefox, I didn't anticipate any issues. But after disabling Sandbox Mode, everything started working like a charm.

It's puzzling why Sandbox Mode is causing this issue specifically with Chrome.

Answer №2

Your coding approach in the factory seems a bit unconventional with strange JavaScript: return new function() ... However, it appears to be functioning fine based on your description. I have personally used a similar technique without any issues on Chrome.

Ensure that your Facebook application is properly configured for your domain (let's say "mydomain.com")... In order to test locally, you will need to modify your hosts file to redirect mydomain.com to 127.0.0.1... so that the URL displayed in the browser matches Facebook's expectations.

This setup difference might be the only discrepancy between our approaches.

... Also, verify that your App ID corresponds to the correct one from setting up your Facebook Application. It's crucial to double-check this as using incorrect or dummy "test" App IDs can also trigger error messages.

-

-


EDIT: regarding the use of new function(){ }... which doesn't seem to be the issue here.... Let me clarify further:

var x = new function() { this.foo = 'test'; };

is equivalent to

var x = { foo: 'test' };

Since the new keyword is utilized to invoke a function as an object constructor, and in this case, you're creating a new instance of an anonymous function which won't be reused, hence there's no necessity to declare it.

Therefore, your code snippet could (and probably should) be written as:

.factory('facebookConnect', function() {
    return {
        authenticate: function(fail, success) {
            FB.login(function(response) {
                console.log(response);
                if (response.authResponse) {
                    FB.api('/me', success);
                } else {
                    fail('User cancelled login or did not fully authorize.');
                }
            });
        }
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to deactivate select option(s) based on the JSON data retrieved through AJAX?

I am facing an issue with a dropdown menu that contains several options. My goal is to loop through these options and set the disabled attribute on specific ones based on the result of an Ajax call. https://i.sstatic.net/9k3f9.png This is what I am tryin ...

leveraging the default browser behavior for the href and target attributes within an <a> element in Angular 2

How can the behavior of a simple anchor tag in Angular 2 be implemented without being overridden by the routing module? <a href="some url" target="_whatever"> It is crucial to prevent the routing module from highjacking the URL using the base href. ...

The combination of jQuery, using .load method in javascript to prevent scrolling up, making XMLHttpRequest requests, updating .innerHTML elements, and troubleshooting CSS/JS

While utilizing this code, CSS and Javascript are disabled (only HTML loads): function loadContent(limit) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status ...

Changing text and applying a different span class using a Jquery button toggle

My current issue involves a functional toggle button that smoothly slides a div up and down. However, I am facing problems when attempting to change the toggle button status: You can view a demonstration of my code here: http://jsfiddle.net/zwu0sn83/3/ B ...

Encountering difficulties when serving assets in Express.js?

I am working with a file structure that looks like this: - server.js - controllers - [...] - public - utils - views - home - index.html - js - index.js - css - index.css When my application starts, I include ...

Is the Router.refresh() function failing to refresh within the next 13 seconds?

'use client'; import { useRouter } from "next/navigation"; export default function Todo({ todo }) { const router = useRouter(); return ( <> <li key={todo.id}> <input type=&apo ...

Convert the easeInExpo function from jQuery easing to vanilla JavaScript and CSS

Currently, I am in the process of converting a piece of code from jQuery to plain JavaScript and CSS. The specific code snippet I am focusing on involves creating easing functions without relying on jQuery. const customEasing = { easeInExpo: function ( ...

Tips for invoking the same directive twice with varying HTML content within the directive

Currently, I am working on a project that involves utilizing AngularJS material. Within this project, I am encountering an issue when calling a directive (<sdiv-panel></sdiv-panel>) twice within the DOM. The problem arises when I make modificat ...

Angular directive and the concept of isolating scopes

I am facing an issue with a directive that dynamically adds divs to the template. Every time I add a new one, the previously created ones are replaced by the new content. I have tried isolating the directive's scope using scope: {} and scope: true, bu ...

Adjusting size and framing of image upon page load using angular directive

I have created a directive that is responsible for rescaling and cropping an image based on its height and width. angular.module('starter.directives', ['starter.controllers']).directive('styleImage', function () { return { ...

Refreshing Angular dropdown menu

Below is the AngularJS code snippet in HTML format: <select name="input_type0" id="select-type-CA0" ng-model="webfront.customer_fields[$index].input_type" class="ng-valid ng-not-empty ng-touched ng-dirty"> <option value="? number:2 ?"&g ...

Leveraging the power of Nuxt.JS (Vue.JS) and VueX to connect a form to an array of objects within a VueX store

Seeking assistance with binding a form to a list of Defaultsettings obtained from an array of objects in NuxtJs and VueX. The list of Defaultsettings includes: Name defaultsetting (text) Active (a switch button that determines if the defaultsetting will ...

Troubleshooting Issue: Incompatibility between AngularJS watchGroup() and Service modification

I am currently facing an issue where I cannot seem to watch multiple variables in a Service as they are being changed by other controllers. Here is what I have implemented: angular.module('carApp').controller('CarListCtrl', function ($ ...

Include a single element repeatedly on a single webpage

Is there a way to add the same component multiple times on one page? I have an input component that receives props and performs certain functions. I need to include more than one instance of this input component on a single page, but when I try to copy and ...

Storing JavaScript variables in a database: A step-by-step guide

For the past few days, I've been working with CakePHP and trying to save a javascript variable into a MySQL database using AJAX (jQuery). Here's the code I've been using: <!-- document javascripts --> <script type="text/javas ...

The initial click may not gather all the information, but the subsequent click will capture all necessary data

Issue with button logging on second click instead of first, skipping object iteration function. I attempted using promises and async await on functions to solve this issue, but without success. // Button Code const btn = document.querySelector("button") ...

Tips on handling a JSON string alert

Can someone guide me on how to extract a specific value from a JSON string I received in an alert message? The JSON string looks like this: {"Error":true, "data":["not available","somethinghere"]} The JSON string is obtained from an alert using the follow ...

What is the best way to incorporate an "if" statement into my code?

I'm in the process of setting up a section on my website where users can get live price estimates based on a value they input. While I have most of the formula in place, there's one final element that I need to figure out: introducing a minimum f ...

jQuery Ajax fails to serialize the input type file field

Here is the Razor code snippet that I use to return a form to a jQuery function upon submission: @model Slider @{ Layout = null; } @using (Html.BeginForm("AddOrEdit", "Slider", FormMethod.Post, new { enctype = "multipart/form-data" ...

The value of Yargs.argv is consistently displayed as [object Object]

In my Ubuntu 16.04 environment, I enrolled in a node.js course on Udemy. Following the instructor's guidance, I initially used the exact version mentioned and later updated to the latest version (11.0.0). Surprisingly, both versions yielded the same o ...