2

I am trying to write a Chrome extension which detects process crashes.

First i went to about:flags page of Chrome and enabled "Experimental Extension APIs".

This is the extension I wrote:

manifest.json:

{
  "manifest_version": 2,
  "name": "CrashDetect",
  "description": "Detects crashes in processes.",
  "version": "1.0",
  "permissions": [
    "experimental","tabs"
  ],
  "background": {
    "scripts": ["background.js"]
  }
}

backround.js:

chrome.experimental.processes.onExited.addListener(function(integer processId, integer  exitType, integerexitCode) {
  chrome.tabs.getCurrent(function(Tab tab) {
    chrome.tabs.update(tab.id, {url:"http:\\127.0.0.1\""});
  };)
});

Then I visited about://crash page of Chrome. But onExited listener does not execute. Have I done anything wrong in manifest.json or background.js?

jszumski
  • 7,430
  • 11
  • 40
  • 53

1 Answers1

1

There a couple errors in your code. First you have the types of the parameters in the function declaration, change it to:

function(processId, exitType, integerexitCode){

Second, you put };) instead of });. Try inspecting the background page to see syntax errors.


Alright, after playing around with it some as I was unfamiliar with this particular API, I found that none of the events fired if I didn't include a handler for onUpdated. I really doubt that this is the intended behavior and I will check to see if there is a bug report on it. For now just do something like this to get it working:

chrome.experimental.processes.onUpdated.addListener(function(process){});

chrome.experimental.processes.onExited.addListener(function(processId, exitType, integerexitCode){
    chrome.tabs.query({active:true, currentWindow:true},function(tabs){
      chrome.tabs.update(tabs[0].id, {url:"http:\\127.0.0.1"});
    });
});

Notice that I did swap out your getCurrent for a chrome.tabs.query as the former would have given you an error. This does lead to the behavior of if you close a tab, the next tab will be redirected. Perhaps you could try to filter by exitType and not include normal exits.

Community
  • 1
  • 1
BeardFist
  • 8,031
  • 3
  • 35
  • 40