I need some help finding out why my code is running on Chrome and isn't on IE 11.
Here is my problem :
Using AngularJS and ngCookies I can set and get my cookies when I use Chrome.
When I use IE 11, the code is not working the same. For example :
var myObject = { "prop" : "value" }
$cookies.put("MyCookie",JSON.stringify(myObject),{})
console.log(JSON.parse($cookies.get("MyCookie"))) // Syntax Error
The cookie is created since I can see it in network/cookies in developer tools
But I can't read it , and I don't know why.
Is IE11 requiring the 3rd parameter of $cookies.put() to be filled with values ?
Related
I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit and asble to get data. But now i am using webview2 is there a how can i get this.
Gecko browser:
using (AutoJSContext context = new AutoJSContext(browser.Window))
{
var userIdResult = context
.EvaluateScript("userId", (nsIDOMWindow)browser.Window.DomWindow);
}
Above is the code I use in gecko browser. now i need to get user id from webview2. Please help me in this issue
I am not able to get any alternative
You can use CoreWebView2.ExecuteScriptAsync to inject script into the current top-level document of the WebView2 and receive the result as a JSON string. The method doesn't have a way to specify an execution context. Script is executed in the global context of the top-level document similar to running script in the console of DevTools in the browser.
For example something like the following:
var resultAsJSON = await coreWebView2.ExecuteScriptAsync('window.userId');
Was trying to test geolocation function in my React project on Firefox 74.0 on Linux Mint 19.3.
When trying to execute the following code:
window.navigator.geolocation.getCurrentPosition(
position => console.log(position),
err => console.log(err)
);
The following error was shown in the Firefox browser console:
GeolocationPositionError { code: 2, message: "Unknown error acquiring position" }
About a year ago Google changed its policies, so now it requires a valid API key when accessing their geolocation service.
If you type in your Firefox address bar:
about:config
and search the following:
geo.provider.network.url
you will see that its value is set to
https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_LOCATION_SERVICE_API_KEY%
This tells us that you need a valid API key in place of %GOOGLE_LOCATION_SERVICE_API_KEY%
Until Mozilla solves this issue internally, the best solution is to change that value to:
https://location.services.mozilla.com/v1/geolocate?key=test
Note: This solution is best for testing. For production you can try ajax calls using either fetch or axios in React.
I'm trying to listen to a MessageEvent sent with postMessage in my Angular 2 component.
My first attempt was simply doing:
window.addEventListener("message", this.handlePostMessage.bind(this));
And then in ngOnDestroy:
window.removeEventListener("message", this.handlePostMessage.bind(this));
However this didn't work as expected. If I navigated to another route and back, there would be two event listeners registered.
So instead I've been trying to decorate the method with HostListener, but I can't get this working when using prerendering (Angular Universal with .NET Core using the asp-prerender-module).
#HostListener('window:message', ['$event'])
private handlePostMessage(msg: MessageEvent) {
...
}
That gives me the following error on page load:
Exception: Call to Node module failed with error: Prerendering failed because of error: ReferenceError: MessageEvent is not defined
Is there a workaround for this?
You're getting this error because MessageEvent is not defined. You must import whatever file defines this.
My #HostListeners look like this:
#HostListener("window:savePDF", ["$event"]) savePDF(event) {
this.savePDFButtonPushed();
}
and you can read more about them here:
https://angular.io/guide/attribute-directives
However, I'm currently experiencing the same issue you are -- that if I navigate to another route and back, I now receive two events. And that is using #HostListener. :-( However I haven't upgraded Angular in a while (currently using 4.4.6), so maybe they've fixed it since that release.
**Edit: Just upgraded to Angular 5.1.0. The 'duplicate events' #HostListener issue remains. :-(
Edit #2: I tried also using window.addEventListener like you tried, and also had the same issue, despite using window.removeEventListener in ngOnDestroy().
This lead me to dig a little deeper, where I found some code I had added to listen to messages from a child iFrame. Any chance you have something similar in your code?
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to messages from child window ("unsign" and "savePDF") and pass those along as events to Angular can pick them up in its context
eventer(messageEvent,function(e) {
window.dispatchEvent( new Event( e.data ) );
},false);
This had been in my page's constructor. I protected it so it only executed the first time the page was constructor, and now all is well.
I discovered a strange error today that only appears when loading:
localhost:9000 and only on Chrome!
AND http://parke.linkpc.net:9000/ works fine on Chrome!
AND localhost:9000 works fine on Firefox.
I went back many builds and still see the same, so this has something to do with the hostname not specified? Note I have cleared chrome cache etc. but no help.
This happens when by 'Auth' service is being instantiated and calling:
$cookieStore.get('token'))
which calls:
$cookieStore.get('token'))
and then when it is attempting to parse a cookie at the code:
getObject: function(key) {
var value = this.get(key);
return value ? angular.fromJson(value) : value;
},
value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1NzY5ODI5Y2MyZjU5NGM0NWQwNjMxODkiLCJyb2xlIjoiYWRtaW4iLCJpYXQiOjE0NjY1MzI1NDAsImV4cCI6MTQ2NjU1MDU0MH0.Vm9GtPMxts1915J6UIzQtDDJ8LvXUKcbWrRxT8jQWzk"
It crashes with:
"Unexpected token e in JSON at position 0"
Why is this? And why only on Chrome?
NEXT: I deleted all the cookies and the problem went away. And I cannot generate it a second time. So go figure.... But it would be nice to know what could cause this issue!
Change the name of key 'token'.
Example:
$cookieStore.get('authKey'))
Instead of:
$cookieStore.get('token'))
Is there something else to configure for url mapping to get it working ?
When I type a wrong url in the browser the Chrome console show the error
GET http://localhost:8081/aaa 404 (Not Found)
EDIT:
and in the Grails console I see :
INFO myApp.ProjectController - Entering Action /project/index
But no redirection is doing to the error.gsp view. I tried to change with : "404"(view:'/') with no success.
Notice I use Angularjs in that project but only in one page for the moment.
Thanks for your help
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"404"(view:'/error')
}