Issue using chrome tabs api, can't use chrome.tabs.move - google-chrome

So, originally I was trying to use the chrome tabs api on my new tab extension, (which has the tabs permission) in order to move the current tab one space backward (to the left), When I tried entering chrome.tabs.move(with all my data in here), it said no matching signature
I have tried playing around with console logging and rereading the api page
Here is the API Page: https://developer.chrome.com/extensions/tabs#method-move
chrome.tabs.getCurrent(
function(currentTab){
chrome.tabs.move(currentTab.id, currentTab.index-1);
}
);
I expected it to run and the current tab to moved but I got this message:
index.html:1 Error handling response: TypeError: Error in invocation of tabs.move([integer|array] tabIds, object moveProperties, optional function callback): No matching signature.
at :3:23

You are calling the chrome.tabs.move() function incorrectly.
As documented on the page you linked, the second argument must be an object containing index and (optionally) windowId properties, e.g.
chrome.tabs.move(currentTab.id, { 'index': currentTab.index - 1 })

Related

Tracing redirects with Headless Chrome Developer Tools

I'm using CDP4J, though I expect this question relates directly to Google Chrome DevTools Protocol.
I want to get a list of the HTTP requests made for a webpage and response codes. So that would include the initial request in the main frame and subsequent requests, either made via 3xx redirects or JavaScript-originated navigation.
It's not clear how to do this reliably.
I have tried the following:
Store io.webfolder.cdp.session.Session.getFrameId
Add callback to session with addEventListener, record every event of type io.webfolder.cdp.event.Event.NetworkResponseReceived
Of these, filter those whose frame ID matches.
Of these filter on type io.webfolder.cdp.type.page.ResourceType.Document
I have a URL that I know returns a HTTP 303. But looking at the Events, don't see the original URL, but instead see only the final destination of the redirects. Every single NetworkResponseReceived has a status of 200.
How can I capture the chain of redirects?
I found the answer. The io.webfolder.cdp.event.network.RequestWillBeSent event has getRedirectResponse, which contains a response if it's a redirect.
I've been using the ResponseReceived event for this purpose. This seems to work to get the document URL from the event:
if (session.getTargetId().equals(responseReceived.getFrameId()) && ResourceType.Document.equals(responseReceived.getType())) {
String url = responseReceived.getResponse().getUrl();
...
}

Using chrome.runtime.sendMessage without the extensionID

I'm working on a project that needs to use an extension that a customer must download and install, however my web page needs to communicate with the extension, so i use the documented way:
https://developer.chrome.com/extensions/runtime#method-sendMessage
chrome.runtime.sendMessage(string extensionId, any message, object options, function responseCallback)
{
...
}
This means i have to include the "extensionId" of an extension that only generates this code once its installed.
Doesn't this sound a little "cart before the horse"?
I have to explain this to our clients, how to go and get their extension ID, and some how apply it to this page in order for it to work? Its seems terribly clumsy, especially since i have have to set the permissions explicitly.
"externally_connectable": {
"matches": ["*://mywebsite.com/*"]
},
If I omit extensionId, it doesn't work.
"Uncaught Error: Invalid arguments to connect"
According to the link you posted, it says extensionId is optional and that it is "[t]he ID of the extension/app to send the message to. If omitted, the message will be sent to your own extension/app." So it seems that it should still work even without the extension ID.
Having said that I noticed the same error on an extension I'm trying to debug, but it seems to be all working despite it. And when I add the extensionId the errors disappear. Might need to find a way to access the extensionId from within the extension.
Update: I successfully substituted in '##extension_id'. See this.

Chromium + Raw Html (directly from a C# string) + Angular => Problems when attempting to use routing

CefSharp: 1.25.0 (based on Chromium 25.0.1364.152)
Angular: 1.3.0-beta16
UIRouter: 0.2.10
I'm developing a stand-alone C# application that uses CefSharp Chromium + Angular + UIRouter as the stack upon which the GUI will be relying on.
I hit it off by trying to make the above stack load the sample-code provided here:
http://scotch.io/tutorials/javascript/angular-routing-using-ui-router
For the sake of elegance the HTML + Javascript-libs of the GUI, get cobundled in a single resource file inside the .Net executable of the application.
This resource is then passed programmatically during application-init to the Chromium control (by means of .LoadHtml) to be loaded directly into the browser, aka the HTML is not loaded from a separate .html file residing in the hard-drive or on a remote HTTP server. If the HTML gets loaded from the later ("standard") venues then everything works flawlessly.
I noticed that when loading the HTML directly as a string, as described above, the url of the resulting static web page (aka window.location) is set to 'about:blank'. It appears that angular has some sort of pet peeve with such a url, especially when it comes to using routing:
First of all, the invocation of:
history.pushState(null, "", url);
inside
self.url = function(url, replace) { ... }
throws an exception ala
Error: SecurityError: DOM Exception 18
Error: An attempt was made to break through the security policy of the user agent.
at Browser.self.url (about:blank:8004:21)
at about:blank:10049:24
at Scope.$eval (about:blank:11472:28)
at Scope.$digest (about:blank:11381:31)
at Scope.$apply (about:blank:11493:24)
at about:blank:6818:15
at Object.invoke (about:blank:7814:19)
at doBootstrap (about:blank:6817:16)
at bootstrap (about:blank:6827:14)
at angularInit (about:blank:6796:7)
the url that is passed to .pushState is:
about:blank#/home
which appears to be the result of concatenating 'about:blank' with the default state '/home'.
Secondly, even if the above problem is solved there appears to be a major issue inside:
$rootScope.$watch(function $locationWatch() { ... })
which causes the following error:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
the reason is that when 'window.location' is set to 'about:blank' then
$browser.url()
always returns
about:blank
while
$location.absUrl()
returns
about:blank#/home
causing $watch to fire non-stop.
Is there any proper way to handle this shortcoming of angular when its dealing with web pages loaded directly into the browser in the manner described here?
If there is no workaround for this issue then I'm afraid that I will have to resort to loading the HTML directly from a file in the hard drive, which apart from being slower (can't cache the string to memory for subsequent usages), it's also a noticable deviation from the goal of developing a stand-alone-exe. :(
Thanks in advance and I apologize if this issue has been addressed elsewhere.
By default Firefox allows loading of external files within html file that loaded from "file:///...". but Chrome does not. in CefSharp(Chrome) you can do it in this way:
// Allow angular routing and load external files
BrowserSettings setting = new BrowserSettings();
setting.FileAccessFromFileUrls = CefState.Enabled;
browser.BrowserSettings = setting;
this.Controls.Add(browser);
Most browsers don't allow to do AJAX on the file-system. But Chromium can be tweaked to do so:
browser = new ChromiumWebBrowser(path);
browser.BrowserSettings = new BrowserSettings();
browser.BrowserSettings.FileAccessFromFileUrlsAllowed = true;

chrome.webstore.install() failure detail string error codes?

I can't seem to find the failure detail string error codes for chrome.webstore.install() 's failure callback... For that matter, I'm not sure if there's documentation for this part of Chrome app development??
From https://developers.google.com/chrome/web-store/docs/inline_installation#triggering
This function [the failure callback] is invoked when inline installation does not successfully complete. Possible reasons for this include the user canceling the dialog, the linked item not being found in the store, or the install being initiated from a non-verified site. The callback is given a failure detail string as a parameter. You may wish to inspect or log that string for debugging purposes, but you should not rely on specific strings being passed back.

swfaddress setValue() with amazon s3 bucket

For my flex apps deeplinking, I use swfaddress 2.4. It works before but now problem occurred when I migrate my flex apps to be hosted on Amazon S3 bucket.
I have done this:
policy file set on each domain that the app will access to load assets/data
allowScriptAccess is set to always
the policy files are loaded (via loadPolicyFile) when the apps is initiated
allowDomain (and allowInsecureDomain) also been set
The problem:
when calling SWFAddress.setValue(), the address on browser address bar is never been changed. When debug, the _value in swfaddress.js is correctly holding the value that been passed
this breaks browser history (back button in broswer and the apps can't be used)
manually enter a query into adddress bar throws this error:
Uncaught Error: Error in Actionscript. Use a try/catch block to find error.
and
Uncaught Error: Error calling method on NPObject
which is from the function _swfChange in line: obj[setter](value); where setter is the setSWFAddressValue callbacks in SWFAddress.as. So, I had even made the SWFAddress.as to execute _initialize function where it adds the callbacks
whe i put the try..catch at the problematic line, it goes into the infamous infinite-loop swfaddress problem. Adding a fix to that like recommended, now the apps didn't change the view state
Thanks in advance.
//btw, it's similar to this unsolved probleem: Amazon S3 and swfaddress