Communication between rails application and chrome app - ruby-on-rails

Currently working on a rails application , i want to send and receive data to this chrome application https://github.com/GoogleChrome/chrome-nfc.
I added chrome.runtime.sendMessage() function inside app.js file to send a simple "hello world" to my browser and
chrome.runtime.onMessage.addListener(function(response,sender,sendResponse){alert(response);});
to show it but I get nothing.
Is it the right way to communicate between them ?

Are you using near field (NFC)? If not, you may want to do something much more simple to pass info between your Chrome App and Rails on server, use an XHR request:
https://developer.chrome.com/apps/app_external#external

Related

Why does my Heroku Open App Button Not Work?

When in the Heroku development environment looking at my project, I click on the Open App button and the page never loads. I believe this is connected to a bug in my iOS application
I'm a beginning developer working on an iOS app that uses a Heroku server to interact with the Venmo SDK. I deployed the server (written in Node.js) successfully, but I'm new to that language and much of it was done with tutorials and sample code, so I'm not sure how a lot of it works.
I have a line of code that accesses the servers page (something along the lines of "xxxxxx-server.heroku-app.com", but it fails every time. Since the heroku app has successfully deployed, I think the fact that I can't open it is related to this error.
Below is a sample piece of my iOS application in Swift 4 that tries to access my server:
func fetchClientToken() {
// TODO: Switch this URL to your own authenticated API
let clientTokenURL = NSURL(string: "https://barhop-server.herokuapp.com/client_token")!
I expected this to work because this is the URL of my server. Any suggestions would be greatly appreciated. Thanks.

Previewing rails server on AWS Cloud 9: VFS Connection does not exist [Firefox only]

Update: This is specific to Firefox. This does not occur using Chrome. I will leave the text below as is, but now the main question is, how and what in Firefox is causing this. It occurs regardless of cookie settings, such as allowing third-party cookies and trackers.
Preface: I've searched and read dozens of pages trying to resolve this issue I've gone through all the troubleshooting steps in the AWS documentation, eg,
https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share
and this thread:
https://forums.aws.amazon.com/message.jspa?messageID=849200 as well as resources on stackoverflow
and the c9 forums
https://community.c9.io/t/what-is-vfs-connection-does-not-exist-on-aws-c9/22697/4)
I am trying to preview a running rails app from the Cloud 9 IDE. When I run the app using rails server, there are no error messages indicating anything wrong. The output shows Started GET '/' for [my home IP] ...... 200 Completed OK.
Console Output:
Trying to preview the running app only produces a "OOPS VFS connection does not exist" screen. The preview url is always https://[user_generated_sequence].vfs.cloud9.[region].amazonaws.com/ All TCP traffic is allowed as per the rules set up by following the troubleshooting guides.
OOPS error message page:
The same issue occurs whether using puma or WEBrick. With WEBrick, a popup for the preview link appears, but leads to the same error message page. With puma, the running app is listening on tcp://[localhost/0.0.0.0]:[8080 or 3000]. With WEBrick, it listens instead on http://localhost:8080.
I have followed the instructions exactly in the rails tutorial to set up a simple app. Everything in the code itself should be fine. How can I get this to work correctly? I'm very confused and about to give up on rails.
I recently had the same issues after updating Firefox because cross-site cookies are required to preview a running rails application. If, like me, you have disabled that in Firefox as part of strict Enhanced Tracking Protection, they will need to be enabled at least for this specific site.
Make sure you are accessing the preview from the same browser:
This URL works only when the IDE for the environment is open and the
application is running in the same web browser
https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-preview-app
Something that worked for me, do the following:
run:
rails s
the in the AWS EDE click on 'Preview' and 'Select Running Application'
Once it will open click on the button/link and it should open in another window with the running application.
Note: Doing this manually by copying the URL link and pasting in another tab did not work for me.
Try disable Ad Blockers and privacy Extention. It worked for me.
Basically you need to allow third party cookies
in chrome it's
Settings >> Security >> Cookies and web data >> Choose second option(block cookies only in incognito)
That works for me
On cloud9, click the shield logo in the address bar and switch "Enhanced Tracking Protection" to be off. Then refresh the page and the preview.
I was struggling with this as well. Finally, I changed the cookie setting from all third-party cookies to cookies from unvisited sites (See image)
Cookie Settings for Firefox

iOS devices with browsers such as Chrome can't handle a 204 response. For my Flask app, what alternatives do I have?

I noticed that my Flask app when accessed via Chrome on an iOS device cannot handle an empty response, return 204, correctly. It redirects to a blank page. The intention (as it works on Android and a Windows desktop with any modern browser) is to play the JavaScript animation, and to POST data. Since Chrome and other browsers have not issued a fix for over 4 years, what alternative do I have with Flask for POST'ing the data and remain on the page with Flask? The method does need to return something, after all.
Edit: The current suggested solution does not appear to solve my issue, as the results are the same after implementing e.preventDefault() for my jQuery that is submitting the form.
I learned that I could simply perform an Ajax call instead of relying on the return 204. I POST'd the data with Ajax and had Flask return with a 200.

open url with your app and pass params

I'm developing two versions of app(android, and ios)
In android when i open url from email the system gives me several options of opening it: browser, my app.
I can open the url(http://www.someurl/path?param1=2&param2=1) with my application and get the params. Is there a way to do it in ios? thanks in advance

Facebook iOS Mobile Web JS SDK Error

We already have Facebook working on our main desktop app without an issue. When I added the same setup code to our mobile site I received an error from the JavaScript SDK:
Received message of type object from https://s-static.ak.facebook.com, expected a string
Then, I changed the setup code to an exact replica from here: https://developers.facebook.com/docs/guides/mobile/web/ and received the exact same message.
This error only shows when the user-agent is iOS or Android in Chrome Developer Tools or in the iOS Simulator. When it's running from the desktop, we aren't seeing this error.
Any idea what's going on here?
Thanks :)
With all due respect, I believe that bokonic's answer is missing the point. The immediate reason of the message you're receiving is most likely javascript postMessage method. It is used to communicate your website with an object returned by window.open or an iframe's embedded website.
window.parent.postMessage(message, targetOrigin);
You might want to have a look at this article to see how it works.
According to MDN reference first argument of the postMessage method can be of any type. Still, Prior to Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the message parameter must be a string.
I tested the method on Chrome 28.0.1500.72 (latest version when writing this answer) and it works fine when passing an object but still throws the warning message to the console. I believe that facebook feels uncomfortable with passing some rich data as a string so they pass it as an object and simply doesn't care about the warning. Or, since there is a workaround (e.g. JSON.stringify), they have a bug they don't know about.
I had the same error. This isn't necessarily the reason you're getting it, but I ended up looking at the packets being received by my iphone simulator, and here's the error from s-statick.ak:
[truncated] <span>Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one o
For me, the error is that on my device(s), I'm accessing the site through an ip address (192.168.xx etc) and on local development I have hosts routing localhost to a url that is in my facebook app config... so the IP isn't configured for the app.
Facebook won't let me use an IP address, so it seems like the only option is a test deploy or a DNS server. Hope this helps you out.

Resources