Update the way of checking if gerrit is ready

As of M80, native support of htmlImports is removed,
replaced with polyfill from webcomponentsjs.
One of the biggest change is switching from
sync to async which will affect quite a lot on how
we load plugins.

As Gerrit should be ready once header shows up,
here replaced the old checking on # of imports to
the readiness of #mainHeader

Change-Id: I351c4ddb4abf8fb5fb5d5f57bd5986c593357283
diff --git a/release-notes.md b/release-notes.md
index 949e7dd..c3b2f9f 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -1,3 +1,7 @@
+#### v0.0.4
+
+- A better way to wait for Gerrit when injecting html plugins
+
 #### v0.0.3
 
 - Hotfix
diff --git a/src/content_script.ts b/src/content_script.ts
index 1e3c978..0caabb6 100644
--- a/src/content_script.ts
+++ b/src/content_script.ts
@@ -7,15 +7,18 @@
 }
 
 // Since content-script can not access window.Gerrit,
-// here checks the readiness based on # of imports
-// (as plugin will inject more html imports once added)
+// here checks the readiness based on #mainHeader element
 const onGerritReady = async () => {
-  let importLinks = document.querySelectorAll("link[rel=import]");
-  let gerritReady = importLinks && importLinks.length > 2;
-  while (!gerritReady) {
+  let header;
+  try {
+    header = document.querySelector("#app").shadowRoot.querySelector("#app-element").shadowRoot.querySelector("#mainHeader");
+  } catch (e) { }
+
+  while (!header) {
     await nextTick(1000);
-    importLinks = document.querySelectorAll("link[rel=import]");
-    gerritReady = importLinks && importLinks.length > 2;
+    try {
+      header = document.querySelector("#app").shadowRoot.querySelector("#app-element").shadowRoot.querySelector("#mainHeader");
+    } catch (e) { }
   }
   return true;
 }
diff --git a/src/manifest.json b/src/manifest.json
index 6b1e22c..faec7c2 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -2,7 +2,7 @@
     "manifest_version": 2,
     "name": "Gerrit FE Dev Helper",
     "description": "This extension can help you development on gerrit sites, frontend specifically",
-    "version": "0.0.3",
+    "version": "0.0.4",
     "browser_action": {
       "default_icon": "gray-32.png",
       "default_title": "Gerrit FE Dev Helper"