Webview browser application not open the dynamic links of Google Forms either dynamically or directly - dynamic

I built a Webview browser application on an Android 11 device that knows how to open all links perfectly! But it does not open the dynamic links of Google Forms either dynamically or directly (when I copy the final address that opens on my computer), the application completely crashes and closes! I did not find any useful information on Google only regarding dynamic links to Firebase - I added the functionality as required, but to no avail! For Dodge:
Dynamic: https://forms.gle/uJq3pGPJhqZGYzLC6
, Direct: https://docs.google.com/forms/d/e/1FAIpQLSd8PZt648GmhALFyykBTflSiU8b9_e-h3gVfY6ZBcF9-N0HbQ/viewform
Dynamic: https://docs.google.com/forms/d/e/1FAIpQLScnkyROLo8VavCmaRagZb6eiucxjCdkOs6blijHwe34vFXO6g/viewform?usp=sf_link ,
direct: https://docs.google.com/forms/d/e/1FAIpQLScnkyROLo8VavCmaRagZb6eiucxjCdkOs6blijHwe34vFXO6g/viewform
I tried to add dynamic links to the firebase SDK, and In AndroidManifest.xml, add an intent filter to the activity that handles deep links for your app. And I also called to call the getDynamicLink() in OnCreate() but the links never reached this event.
Direct reading ON 'shouldOverrideUrlLoading' didn't help either because the application crashes before it gets here, that is, something goes wrong with the dynamic search and even in debugging it disrupts the URL completely:
public boolean shouldOverrideUrlLoading (WebView view, String url) {
if(url.contains("https://docs.google.com/forms/") && url.contains("/viewform"))
{
try {
url= "https://"+ url.split("https://")[url.split("https://").length-1].split("viewform")[0].trim()+"viewform";
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
url = "https://www.google.com";
}
}
mWebView.loadUrl(url);
return true;
}

Related

How should I run a background task that also updates the UI in an intellij settings plugin

I am adding some changes to an intelij plugin that integrates with vault I have settings page that implements Configurable that has a form for credentials and then a "Test Login" button. On button click I want to spawn an asynchronous background task to test the credentials and then update the UI with either success or failure.
Here is a screenshot of my settings
As far as I can tell the correct way to do this would be to use a background task but that requires a "project" which as far as I can tell you have to get from an AnAction and I don't really see how that would work in this context. Here are a few approaches I've played around with
This still blocks the UI and spits out a warning about the UI being blocked for too long
ApplicationManager.getApplication().executeOnPooledThread(() ->
ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> {
// async work
// repaint
}, ModalityState.stateForComponent(myMainPanel)));
// I don't know how to get the project or if I even should here.
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Login"){
public void run(#NotNull ProgressIndicator progressIndicator) {
// async work
// repaint when done
}});
All of this is happening in my AppSettingsComponent button click addActionListener. Here is my complete source code on github
I had the same problem with the project instance required. But by looking at the Task.Backgroundable constructor you can pass a #Nullable project. So I just pass null and it works well for me.
ProgressManager.getInstance().run(new Task.Backgroundable(null, "Login") {
public void run(#NotNull ProgressIndicator progressIndicator) {
// your stuff
}
});

Is there a way to simulate a link/button click in mink?

I'm using a headless browser (phantomjs) in conjunction with Mink to do some functional testing on my Website.
Now in this setting, files can not be downloaded regularly e.g: by clicking a link. So I have to extract the url from the link or the button, and download the file manually.
As I just stated sometimes there is no link () for the download, but a button in a Form (e.g: Inputting data for a report in the form, and receiving the report file on submission).
So what I need to do is simulate clicking the link or button and extract the Data for the Request that would have been sent, and use that data to download the file manually.
Is there a way to do this?
Note: I'm using guzzle to actually download the file.
Mmmm... I don't know if you solved this and only as an alternative to typical mink methods. As Phantomjs is a javascript based browser engine, did you tried with javascript?
You could try something like this:
public function getElementHref($element)
{
/* #var FeatureContext $this */
$function = "(function(){
//Javascript method to get the href.
})()";
try {
return $this->featureContext->getSession()->evaluateScript($function);
} catch (Exception $e) {
throw new Exception('Element not found');
}
}
You can find a method to do this in javascript here: How to get anchor text/href on click using jQuery?
Then use the URL returned with file_get_contents (depending on the file type) and that's it.

How to a hide a page

I have a pop up that is called through a java script, the same pop up without a JavaScript is an ctp page in cakephp. How can I hide that page from users and search engines going to access it like: /users/register
Is there anything that can be done in .htaccess or cakephp to prevent access to it through /users/register
Remove register.ctp file from users folder and create one in ajax folder users/ajax/register.ctp, then use RequestHandler component to inspect request type:
public function register()
{
if($this->request->is('ajax')){
// add registration code here
} else {
//Throw new error
}
}

Worklight 6.1: How to add EULA to hybrid app

Environment:
Worklight 6.1.0.2
dojo 1.9.4
We have created a hybrid app using Worklight 6.1 for android, iOS and windows8 platform. Now we would like to add and show End User License Agreement (EULA) window to the user, when the app first time launch. It should have Accept and Decline button. If user tap on Accept button, then he should be able to use the app.
I would like to know, how can we achieve this using Worklight 6.1.
Any help on this, will be much appreciated.
FYI there is nothing specific here to Worklight.
You could implement this in any number of ways w/out ever using any Worklight API whatsoever.
You could achieve it for example like this (untested code - you'll need to experiment):
In main.js create some global variable eulaAccepted:
var eulaAccepted;
// You will need to handle this property using HTML5 Local Storage so that it will persist for the next time the app is launched, and have the app act accordingly.
Then, in wlCommonInit():
function wlCommonInit() {
if (!eulaAccepted) {
displayEula();
} else {
displayApp();
}
}
In displayEula():
function displayEula() {
// either display a dialog using `WL.SimpleDialog`...
// Or maybe custom HTML with "accept" and "not accept" buttons
WL.SimpleDialog.show(
"Eula Agreement", "your-eula-text-here",
[{text: "Accept", handler: acceptEula },
{text: "Reject", handler: rejectEula}]
);
}
Handle the result:
function acceptEula() {
eulaAccepted = true;
... // Some code that will store the `eulaAccepted` variable using HTML5 Local Storage API
displayApp();
}
function rejectEula() {
// Display some other custom HTML instead of your app.
// Maybe also additional logic to try again to accept the Eula...
}

How can i use the port.postmessage to send info from the background page to the content script in a Google Chrome extension

I've been able to send data from the background page to the content script. but this is done using sendrequest(). I will need to send data back and forth so I'm trying to figure out the correct syntax for using the port.postmessage from background page to content script. I have already read, several times, the google page on Messaging and I don't seem to get it. I even copied the code directly from the page and tested with no result. All I'm trying to do for now is send data from background page to content script using connect as opposed to sendrequest. The response from the content script I will deal with later as code with this response has been the main thorn. I just want to understand the process one step at a time without the extra knowledge of sending a response back.
I'm not sure if this contravenes the rules of this board but can someone PLEASE give me an example of some code to do this (background page and content script excerpt, the background page is the sender).
I've asked for assistance several times on this site only to be told to read the documentation or check out sites I've already visited.
If you just want any example of opening a port from the extension to a content script, here's the simplest I can think of. The background just opens a port and sends "Hello tab!" over the port, and the content script sends a message to the background any time you click on the webpage.
I think this is pretty simple, so I don't know why you are so stressed. Just make sure that the content tab is already listening when the background tries to connect (I do this by waiting until the "complete" event).
manifest.json:
{
"name": "TestExt",
"version": "0.1",
"background_page": "background.html",
"content_scripts": [{
"matches": ["http://localhost/*"], // same as background.html regexp
"js": ["injected.js"]
}],
"permissions": [
"tabs" // ability to inject js and listen to onUpdated
]
}
background.html:
<script>
var interestingTabs = {};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// same as manifest.json wildcard
if (changeInfo.url && /http:\/\/localhost(:\d+)?\/(.|$)/.test(changeInfo.url)) {
interestingTabs[tabId] = true;
}
if (changeInfo.status === 'complete' && interestingTabs[tabId]) {
delete interestingTabs[tabId];
console.log('Trying to connect to tab ' + tabId);
var port = chrome.tabs.connect(tabId);
port.onMessage.addListener(function(m) {
console.log('received message from tab ' + tabId + ':');
console.log(m);
});
port.postMessage('Hello tab!');
}
});
</script>
injection.js:
chrome.extension.onConnect.addListener(function(port) {
console.log('Connected to content script!');
port.onMessage.addListener(function(m) {
console.log('Received message:');
console.log(m);
});
document.documentElement.addEventListener('click', function(e) {
port.postMessage('User clicked on a ' + e.target.tagName);
}, true);
});
Detailed documentation and easy (the most basic) examples shown in the documentation page.
Plus, a quick search in stackoverflow will allow you to see many similar questions with detailed answers.